[英]htaccess for rewrite URL is not working for my website
I have dynamic URL website (irasol.com) while i navigate to menu the url shows like 我有动态URL网站(irasol.com),同时导航至菜单,URL显示如下
http://irasol.com/index.php?id=1 http://irasol.com/index.php?id=1
I want url like this 我想要这样的网址
domainname/home
domainname/aboutus
domainname/contactus
domainname/apply
home, aboutus, contactus, apply are menu name it is already in database. 主页,aboutus,contactus,apply是已经在数据库中的菜单名称。
my htaccess file is 我的htaccess文件是
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^/]*)\.php$ /index.php?id=$1 [L]
Use this instead: 使用此代替:
Options -Multiviews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ index.php?id=$1 [B,L]
Explanation 说明
domainname/aboutus
is not a real file, so that we don't rewrite files that already exist. 前三个条件确保domainname/aboutus
不是真实文件,因此我们不会重写已经存在的文件。 Options -Multiviews
removes a number of potential problems Options -Multiviews
消除了许多潜在的问题 In your current code, get rid of the .php in your pattern: 在当前代码中,删除模式中的.php:
RewriteRule ^([^/]+)$ /index.php?id=$1 [L]
You are not matching .php extensions in the request. 您在请求中不匹配.php扩展名。 You are only routing matches to a query string on a real .php extension 您只将匹配项路由到真实.php扩展名上的查询字符串
As for a better solution: 至于更好的解决方案:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?id=$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.