Forum Moderators: phranque
RewriteRule ^/?([-A-Za-z0-9]+)/?$ index.php?sectionname=$1 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2 [L]
^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9-]+)/?$ index.php?sectionname=$1&categoryname=$2&title=$3 [L]
This rule
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2 [L]
rewrites a url to this
www.mydomain.com/sectionname/categoryname/
The problem that I have is that I have some old pages that I need to redirect to these new pages that I have rewritten urls for
My old page that i want to redirect is like this
www.mydomain.com/myoldsection/myoldcategory/
and I want to redirect it to my new page
www.mydomain.com/tv/video/
It wont work, and seems to add the full url to the end after the slash
like this
www.mydomain.com/section/category/index.php?sectionname=tv&categoryname=video
I have tried everything. It seems that the rewrite and redirect clash due to them workin on the same part of the URL (between the slashes)
I would be really grateful for any tips on how to get around this issue.
Or is there a better way than using htaccess to rewrite?
Cheers
This is likely a problem of rule order and/or mixing directives from mod_rewrite and mod_alias and expecting them to execute in line-by-line order, which they may or may not do, depending on your server configuration.
Also, what version of Apache are you on?
Jim
Many thanks for your help
Here is my full htaccess file
I have to put some words in between the slashes to make sure the rewrites work, so this doesnt work as it stands at the moment.
For instance: ([-A-Za-z0-9]+)my-product-page
e.g.
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)my-product-page/?$ index.php?sectionname=$1&categoryname=$2 [L]
I didnt realise the order in which they appear would matter. Is it possible to not have any of these rules clashing at all then? And will it be possible for me not to use the "my-product-page" in the URL?
Again many thanks for your help :)
Z
Options +FollowSymLinks
RewriteEngine OnRewriteRule ^_([-A-Za-z0-9]+)/?$ index.php?page=$1 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/?$ index.php?sectionname=$1 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/_([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&page=$2 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/_([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&page=$3 [L]
## This seems to be the problem line, when I remove it the redirect works.
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9-]+)/?$ index.php?sectionname=$1&categoryname=$2&title=$3 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&ordertype=$3 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)/_([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&ordertype=$3&page=$4 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/_([A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4&page=$5 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4&ordertype=$5&filter=$6 [L]
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/([A-Za-z0-9]+)-([-A-Za-z0-9]+)/_([A-Za-z0-9]+)/?$ index.php?sectionname=$1&categoryname=$2&filterfield=$3&filter=$4&ordertype=$5&filter=$6&page=$7
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule .index.php
Redirect 301 /tv/video http://www.mydomain.com/newtv/newvideo
This may not be a coding problem at all -- it may simply be that there is a logical inconsistency buried in all those "slashes and dashes" that is causing unexpected operation. The "visual clutter" makes it very hard for anyone not intimately familiar with your URL-patterns to discern.
Short, focused questions generally get quicker responses, while long code dumps may have to wait for the weekend...
By using directives from two modules -- both mod_rewrite and mod_alias, you lose control over which directives are processed first. I'd suggest re-coding that redirect using mod_rewrite, and placing it above your other rules:
RewriteRule ^tv/video(.*)$ http://www.example.com/newtv/newvideo$1 [R=301,L]