Forum Moderators: phranque
RewriteRule file/mid/(.*)/ file.php?mid=$1
RewriteRule file/mid/(.*) file.php?mid=$1
The problem now is that due to some external links pointing to the wrong version of the page, i now have 2 versions of some files in the google index.
Example of what i mean :
http://www.example.com/a-file/mid/478 - wrong version
http://www.example.com/a-file/mid/478/ - right version
http://www.example.com/a-file/mid/599 - wrong version
http://www.example.com/a-file/mid/599/ - right version
My right version file is with the ending slash.
How do i write a rule to redirect permanently all the wrong version (without slash) to right version (with slash) keeping in mind the existing rule above. So that i can remove the second rule (RewriteRule file/mid/(.*) file.php?mid=$1) that caused the problem.
Please guide me.
Thanks
[edited by: jdMorgan at 4:12 pm (utc) on Sep. 8, 2007]
[edit reason] example.com [/edit]
# Externally redirect /file/mid/<file> requests to add a trailing slash if it's missing
RewriteRule ^file/mid/([^/]+)$ http://www.example.com/$1/ [R=301,L]
#
# Externally redirect direct client requests for the /file.php script back to the 'friendly' URL
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /file\.php\?mid=([^&]+)
RewriteRule ^file\.php$ http://www.example.com/file/mid/%1/? [R=301,L]
#
# Internally rewrite /file/mid/<file>/ requests to the script /file.php?mid=<file>
RewriteRule ^file/mid/([^/]+)/$ /file.php?mid=$1 [L]
Thanks for the help.
First of all i tried using the follwing to see if it adds a trailing slash:
# Externally redirect /file/mid/<file> requests to add a trailing slash if it's missing
RewriteRule ^file/mid/([^/]+)$ http://www.example.com/$1/ [R=301,L]
Nothing happened, there was no slash been added.
Then i realised that you missed put putting file/mid after www.example.com. So i modified the rule to:
RewriteRule ^file/mid/([^/]+)$ http://www.example.com/file/mid/$1/ [R=301,L]
Still nothing happened.
Then i thought its on the same domain so let me do the following:
RewriteRule ^file/mid/([^/]+)$ ^file/mid/$1/ [R=301,L]
Again nothing happened
Then i did:
RewriteRule file/mid/([^/]+)$ ^file/mid/$1/ [R=301,L]
This time the slash is added but the final url looks like this:
http://www.example.com/home/username/public_html/example/%5efile/mid/478/
Here the full server path is added to the url: "home/username/public_html/example/%5e"
Finally i did:
RewriteRule file/mid/([^/]+)$ http://www.example.com/file/mid/$1/ [R=301,L]
The problem solved partially.
What happended is that the slash is added and the page is displayed full but a part of the url is totally removed. Here is what i mean:
Original URL with Slash : http://www.example.com/variable-file/mid/478
New URL after Slash added : http://www.example.com/file/mid/478
"Variable-" is removed. How do i get this in the url too?
Thanks
RewriteRule ^([^-]+)-file/mid/([^/]+)$ http://www.example.com/$1-file/mid/$2/ [R=301,L]
RewriteRule ^(([^-]+)-)+file/mid/([^/]+)$ http://www.example.com/$1-file/mid[b]/$3/[/b] [R=301,L]
Jim