Dynadot

301 redirect htaccess headaches

Spaceship Spaceship
Watch

whitebark

Part-Time ZombieVIP Member
Impact
152
Been beating my head against the wall trying to get some 301 redirects to work.

Trying to get:
www.example.ca/index.php?name=News&file=article&sid=1
www.example.ca/index.php?name=News&file=article&sid=150
to 301 to
www.example.ca/article-title/
www.example.ca/different-title/

etc

Code:
RewriteCond %{HTTP_HOST}  ^www\.example\.ca$ [NC]
RewriteCond %{QUERY_STRING}  ^name=News&file=article&sid=1(&.*)?$ [NC]
RewriteRule ^index\.php$ http://www.example.ca/article-title/?%1 [R=301,NE,NC,L]

RewriteCond %{HTTP_HOST}  ^www\.example\.ca$ [NC]
RewriteCond %{QUERY_STRING}  ^name=News&file=article&sid=150(&.*)?$ [NC]
RewriteRule ^index\.php$ http://www.example.ca/different-title/?%1 [R=301,NE,NC,L]

The above is where I am at now.

~ Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Well you cannot go on and on writing each new line for each new article that you post.

Also the thing is as you are only passing the Title as parameter the search that needs to take place on article.php side file should be based on that title.

Or else you can use http://www.example.ca/title-of-the-article-1234/

Where the 1234 should be the article ID.

Here is the code.

Code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule .* index.php [QSA,L]

And on the PHP file you can include proper file with the variable fetched that has been passed to it.

Thanks.
 
Last edited:
1
•••
You are absolutely correct "Keral". There are lot many things you can easily manage my your .htaccess file. The change done every time when you add article in not a solution but its an alternative so Keral has suggested the best solution.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back