【问题标题】:user friendly url without filename in core php site核心 php 站点中没有文件名的用户友好 url
【发布时间】:2015-10-22 19:37:21
【问题描述】:

我有一个链接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**

我也想从 url 中删除文件名...

在此先感谢...

【问题讨论】:

  • 请任何人帮助我......尽快......

标签: php apache .htaccess url mod-rewrite


【解决方案1】:

试试这个:

    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]
#___________

【讨论】:

  • 感谢您的回复...但效果不佳....其输出为:www.example.com/Foldername/Foldername/1/Checking,并显示内部服务器错误
  • 您的 htaccess 在您网站的根文件夹中吗?
  • no...在文件夹里面...所以我给了RewriteBase /Foldername/
  • 您的 htaccess 中的 RewriteBase /foldername/ 在哪里?
  • RewriteBase /foldername/ 就在 RewriteEngine On 之后
猜你喜欢
  • 2011-01-07
  • 2021-05-17
  • 1970-01-01
  • 1970-01-01
  • 2017-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多