I have a question. I have spent the last 2 hours searching on the forums and I have not yet found an answer why my htaccess configuration is not working properly.
Here is my .htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.myserver.com/$1 [R]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^block/([a-zA-Z0-9]+)/$ block.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^tx/([a-zA-Z0-9]+)/$ tx.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^address/([a-zA-Z0-9]+)/$ address.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^block/([a-zA-Z0-9]+)$ block.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^tx/([a-zA-Z0-9]+)$ tx.php?id=$1 [L]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^address/([a-zA-Z0-9]+)$ address.php?id=$1 [L]
The RewriteEngine works correctly, I can confirm when launching http:...myserver.com it gets redirected to https:...myserver.com.
However my SEO friendly URLS just don't work. When launching https://myserver.com/block/12345 i only get an error message in my error.log:
[Tue Jan 07 22:08:07 2014] [error] [client 77.186.33.111] File does not exist: /var/www/block
So obviously it did not rewrite anything.
I would appreciate any help, I must be doing something substantially wrong, but for gods sake I cannot figure out myself.
Thanks
You're getting 404 because RewriteRule
expects a trailing slash but your URI doesn't have one.
Replace your code with this and try again:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.myserver.com/$1 [R,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?id=$2 [L,QSA]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.