核心php网站中没有文件名的用户友好网址

时间:2015-07-31 07:48:19

标签: php apache .htaccess url mod-rewrite

我有一个链接 www.example.com/folder/filename.php?cid=1&title=Chekcing

我想通过以上链接将用户友好的网址设为: www.example.com/folder/1/Checking/

我有.htaccess代码:

**

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
     RewriteBase /

    RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\s [NC]
    RewriteRule ^ %1 [R,L]
    RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?cid=([^&\s]+)\&title=([^&\s]+) [NC]
    RewriteRule ^ %1/%2/%3? [R,L]
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^(.+?)/([^/]+)/?$ $1.php?cid=$2&title=$3[QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^(.*?)/?$ $1.php [L]

**

但它只返回没有.php的文件名:**www.example.com/folder/filename/1/Checking**

我也要从网址中删除文件名...

提前致谢...

1 个答案:

答案 0 :(得分:0)

试试这个:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On

RewriteEngine On
RewriteBase /foldername/

#Remove .php extensions from php files :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
#__________


#Redirect urls with query strings to cleaner version :
RewriteCond %{THE_REQUEST} /filename\.php\?cid=([^&]+)&title=([^\s]+) [NC] 
RewriteRule ^ %1/%2? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ foldername/filename.php?cid=$1&title=$2 [QSA,L,NC]
#___________