I want to rewrite without changing PHP scripts

Discuss practical ways rearrange URLs using mod_rewrite.

I want to rewrite without changing PHP scripts

Postby senthil_sivanath » Sat Jan 17, 2009 9:36 pm

Hello everybody

I have developed a site using php, where i need some URL rewrite

I have

Code: Select all
somepage.php?query=value


I need

Code: Select all
/somepage-value.html


When the mod_rewrite is performed there should not be any change to php scripts.(Main difficulty i am facing through this)
senthil_sivanath
 
Posts: 4
Joined: Sat Jan 17, 2009 12:04 pm

Postby richardk » Sun Jan 18, 2009 11:22 am

Mod_rewrite does not change the links in your PHP (or any other) scripts. You have to change them manually by editing the PHP.

The mod_rewrite would be
Code: Select all
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^somepage-([^/]+)\.html$ /somepage.php?query=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Yeah i don't want to edit manually.

Postby senthil_sivanath » Sun Jan 18, 2009 1:49 pm

I don't want edit every single link of entire project.

Is it possible to convert if i type in address bar
somepage.php?id=1 into somepage/id/1.html

i was able to do that with my .htacces but i was not able to get the .html in the end.

it converts the url in the address bar.
senthil_sivanath
 
Posts: 4
Joined: Sat Jan 17, 2009 12:04 pm

Postby richardk » Tue Jan 20, 2009 3:17 am

I don't want edit every single link of entire project.

You should do it anyway. Don't be lazy.

Is it possible to convert if i type in address bar
somepage.php?id=1 into somepage/id/1.html

Yes
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?query=([^&]+)(&.*)?$ [NC]
RewriteRule ^somepage\.php$ /somepage-%2.html? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Trouble Continues.

Postby senthil_sivanath » Tue Jan 20, 2009 7:52 am

Ok. I will edit every single link on my page. So now it will become

Code: Select all
http://mysite.com/articles/1-article-title.html

So every thing is working correct.

And what happens if some one enters

Code: Select all
http://mysite.com/aritcle.php?q=1


in the address bar. It is remaining as it is. Is there any way to convert the text entered in the address bar to .html...... I think this is not possible because i have seen the entire Wordpress project. In that also this exists. Is this a problem. Or it is the correct way?
senthil_sivanath
 
Posts: 4
Joined: Sat Jan 17, 2009 12:04 pm

Postby richardk » Tue Jan 20, 2009 12:53 pm

Mod_rewrite can't redirect /article.php?q=1 to /articles/1-article-title.html because it does not know "article-title". You can do it with PHP or if you have access to the httpd.conf file you could set up a RewriteMap.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Thanks for the reply

Postby senthil_sivanath » Wed Jan 21, 2009 5:03 am

Yeah you are correct. After a lot of googling me too found that. But i don't have access to edit that .conf file because my host won't allow to do that.

We are ready to redesign the project. Will it get good SEO compared to previous.
senthil_sivanath
 
Posts: 4
Joined: Sat Jan 17, 2009 12:04 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 13 guests

cron