我想将我的网址更改为搜索引擎友好。我在64位的Windows 10上使用xampp 3.2.1 我的网址看起来像这样:
http://smc.edu.pk/app/site/?p=12&m=c&u=Swat_Medical_College-_The_Project_of_Swat_Medical_Complex
我想这样做:
http://smc.edu.pk/app/site/12/c/Swat_Medical_College-_The_Project_of_Swat_Medical_Complex.html
我使用.htaccess
测试了以下代码RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/app/site/(\d+)/([a-z-]+)/(.+)\.html$ /?p=$1&m=$2&u=$3 [NC,L]
但是当我使用上面提到的第二个网址时,它会返回以下错误:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
smc.edu.pk
Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
答案 0 :(得分:1)
我认为它应该是这样的(未经测试):
RewriteRule ^/app/site/(\d+)/([a-z-]+)/(.+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
编辑:它应该是这样的(测试和工作):
RewriteRule ^app/site/(\d+)/([a-z-]+)/(.+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
答案 1 :(得分:0)
是的,我找到了解决方案:
RewriteEngine On
RewriteBase /app/site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
我已将RewriteRule更改为:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
并将RewriteBase / app / site /放在第二行。 现在它工作得很好......