Forum Moderators: phranque
[edited by: incrediBILL at 9:34 pm (utc) on Oct 7, 2012]
[edit reason] fixed URLS, use Example.com [/edit]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([-a-zA-Z0-9_]+) /book.php?name=$1 [L] RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^page\.php$ http://example.com/page/%1.pdf [R=302,L]
RewriteEngine On only once. RewriteCond %{REQUEST_FILENAME} !-f ([0-9]*) allows a blank ID. Replace * with + here. ([0-9]+)$ - The $ does not allow for redirecting when there are additional parameters. Use ([0-9]+)(&|$) here. RewriteRule ^book\.php$ http://example.com/book/%1.pdf [R=301,L] RewriteRule ^book/([-a-zA-Z0-9_]+) /book.php?name=$1 [L] Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([-a-zA-Z0-9_]+) /book.php?name=$1 [L]
RewriteCond %{QUERY_STRING} ^name=([-a-zA-Z0-9_]*)(&|$)
RewriteRule ^book\.php$ http://example.com/book/%1? [R=301,L] http://example.com/book/%1.pdf [R=301,L] will obviously redirect to a .pdf URL but I am chasing a extensionless URL this is why I removed the .pdf and added the ?
RewriteCond %{REQUEST_FILENAME} !-f ^name=([-a-zA-Z0-9_]*)(&|$) - the * allows a blank name. Use a + here. Options +FollowSymlinks
RewriteEngine on
RewriteCond %{THE_REQUEST} name=([-a-z0-9_]+)
RewriteRule ^book\.php$ /book/%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([-a-z0-9_]+)(&|$) /book.php?name=$1 [L] %{QUERY_STRING} with %{THE_REQUEST} %{THE_REQUEST} ^[A-Z]{3,9} %{QUERY_STRING} %{THE_REQUEST} haven't I made the query string condition redundnant?, yet it still works? %{THE_REQUEST} ^[A-Z]{3,9} - this part matches the literal GET or POST method found in the HTTP request header sent by the browser: GET /book.php?name=this_one_here HTTP/1.1
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{THE_REQUEST} name=([-a-z0-9_]+)
RewriteRule ^book\.php$ /book/%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([-a-z0-9_]+)$ /book.php?name=$1 [L]
HTTP/1.1 Is this just placed at the end of the redirect target? /book/%1? part should be http://www.example.com/book/%1? RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{THE_REQUEST} name=([-a-z0-9_]+)
RewriteRule ^book\.php$ http://www.example.com/book/%1? [R=301,L]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^book/([-a-z0-9_]+)$ /book.php?name=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^book/([-a-z0-9_]+)$ /book.php?name=$1 [L]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([-a-z0-9_]+)$ /book.php?name=$1 [L]