简体   繁体   中英

url rewrite using php and .htaccess

this question is Basic but important. i need to rewrite php url using .htaccess . ex one : i have many file with .php extension . ex two : i need seo url friendly with name and html extension.

example 1 :

http://mydomain.com/editname.php
http://mydomain.com/location.php
.....

I need to rewrite all to :

http://mydomain.com/editname/
http://mydomain.com/location/

example 2 :

http://mydomain.com/name.php?id=1
http://mydomain.com/state.php?id=1

rewrite to : ( john & bsw is really name and inserted to mysql)

http://mydomain.com/name/1/john.html
http://mydomain.com/state/1/bsw.html

NOTE : If non of this, redirect to 404 not found page.

thanks.

To redirect simple folders to PHP files:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/])/$ /$1.php [L]

And then do redirect your SEO friendly URLs:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/])/([0-9]+)/([^/])\.html$ /$1.php?id=$2 [L,QSA]

The RewriteCond lines check to make sure the request isn't already a valid file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM