Forum Moderators: phranque
^([12][0-9]{3}-[0-9]{2}-[0-9]{2})$, or similar, to partially pre-filter requests. RewriteRule ^daily/([^/]*)/$ /oldstuff.php?date=$1 [L]
queries are ignored in rewrite unless you specifically say to do something about them.
Query string data is automatically re-appended unless you append a different query string or add a question mark to clear the query string.
In your existing code, ([^/]*) allows blank date. You might want ([^/]+) instead.
I would use ^([12][0-9]{3}-[0-9]{2}-[0-9]{2})$, or similar, to partially pre-filter requests.
Whatever you do, make sure the PHP script sends a 404 header for invalid date (like 20A5-890-LA) and for date with no content.
Your two rules allow duplicate content. I would redirect requests "with trailing slash" to "without trailing slash".
RewriteCond %{QUERY_STRING} ^date=2011-06-25$
RewriteRule ^oldstuff\.php$ http://www.domain.com/daily/2011-06-25/? [R=301,L] RewriteEngine On
RewriteRule ^daily/([^/]*)/$ /oldstuff.php?date=$1 [L]
RewriteRule ^daily/([^/]*)$ /oldstuff.php?date=$1 [L] 2011-06-25
Also, when using this code alone I get a 404 error (because no url rewrite is being done.)
"Firefox has detected that the server is redirecting the request for this address in a way that will never complete."
rather than me just doing trial and error
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]
#
RewriteRule ^daily/([^/]*)/?$ /oldstuff.php?date=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /oldstuff\.php\?date=([^\ ]+)\ HTTP/
RewriteRule ^oldstuff\.php$ http://domain.com/daily/%1/? [R=301,L] http://domain.com/daily/2011-06-25 to http://domain.com/daily/2011-06-25/) RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.+) http://www.domain.com/$1/ [R=301,L] RewriteEngine on code. My only question, if a user manually types in domain.com/daily/2011-06-25 (without the trailing slash "/") what's the best way to append this trailing slash "/" to the url with my current setup? (I would like to redirect http://example.com/daily/2011-06-25 to http://example.com/daily/2011-06-25/)
# Enable mod_rewrite, start rewrite engine
Options +FollowSymLinks
RewriteEngine on
#
# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /oldstuff\.php\?date=([^\ ]+)\ HTTP/
RewriteRule ^oldstuff\.php$ http://www.domain.com/daily/%1/? [R=301,L]
#
# rewrite url without index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ http://www.domain.com/ [R=301,L]
#
# append "/" if requested URI contains no filetype and does not end in "/"
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.+) http://www.domain.com/$1/ [R=301,L]
#
# add "www" to beginning of domain name
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
#
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^daily/([^/]*)/?$ /oldstuff.php?date=$1 [L]
# rewrite url without index.php # Redirect index.php requests to slash RewriteBase / RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteCond %{HTTP_HOST} !^(www\.domain\.com)?$ RewriteRule ^daily/([^/]*)/?$ RewriteRule ^daily/([^/]+)/$ example.com/daily// is a valid URL. The + replaces the * here. Additionally, you must allow only ONE URL format, with slash OR without slash to serve the content. To allow both, promotes duplicate content. Delete the question mark. The slash should be required, or should be missing. You decide, though the HTTP specs suggest that "missing" is the correct choice. It is a literal space, to match the "GET /index.php HTTP/1.1" request that the browser sends.