Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mod Rewrite help please

Status
Not open for further replies.

rye8261

Technical User
Jul 6, 2003
359
0
0
US
I have a bunch pages that I'd like to make more seo friendly. I'm not sure the best way to approace this though and need some assistance.

Take for example these two pages:

These pages are in two different places but still have the same variable at the end to get the page. What would be the best way to make it /2 instead of /?page=2

Is there an htaccess I can use or should I use some sort of header redirect? If I use a header does anyone know how to get the variable without having an htaccess in every folder?
 
Hi

rye8261 said:
What would be the best way to make it /2 instead of /?page=2
Code:
RewriteEngine on
RewriteCond %{QUERY_STRING} page=(.*)$
RewriteRule .* %{REQUEST_URI}/%1
rye8261 said:
Is there an htaccess I can use or should I use some sort of header redirect?
I do not understand this. [tt]mod_rewrite[/tt] can both rewrite and redirect. That should be enough.
rye8261 said:
If I use a header does anyone know how to get the variable without having an htaccess in every folder?
The .htaccess file is a local configuration file. If you want to make your settings global, you can put them into the httpd.conf file. But anyway, the .htaccess file's settings are applied recursively in the subdirectories too.

Feherke.
 
Thanks feherke, should I apply a 301 on that? If so do I just make the last line: RewriteRule .* %{REQUEST_URI}/%1 [R=301,L]

 
Hi

Is up to you to decide if you want to redirect and how. But yes, you can do that, it is correct. Although I would not do that. 301 means Moved Permanently and in such cases the page to which you redirect will receive the ranking of the one from which you redirect. And you redirect from a new page with no ranking...

For more post this question in forum828.

Feherke.
 
Feherke,

I've put that code in the htaccess on my test site and when I try to go to the pages with the /?page=X it's taking me to an error page. Do you have any idea why that might be? Do i have to change the code around on the site to display different? The only thing I noticed is the code you put has "page=(.*)$" and not "?page", now I'm not skilled with htaccess stuff so I don't know if the query string part ads the ? or what. If you're not sure, no problem. You've given me a good start.

 
Ok, can you tell me how to fix it?

I tried
RewriteCond page=(.*)$ %{QUERY_STRING}

and it didn't do anything. Sorry I've never really used htaccess before.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top