我想通过htaccess将url从http://localhost/projectname/cab-details.php?v_name=variable
更改为http://localhost/projectname/variable
这里变量是链接(slug(现在我的htaccess代码是
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^$1/([a-zA-Z-0-9-]+) cab-details.php?v_name=$1
使用您显示的示例,请尝试以下.htaccess规则文件。请确保在测试URL之前清除浏览器缓存。
RewriteEngine ON
RewriteBase /omm/
##External redirect rules here.
RewriteCond %{THE_REQUEST} s/(omm/[^.]*).php?v_name=(S+)s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal redirect rules here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^omm/([^/]*)/([^/]*)/?$ $1.php?v_name=$2 [QSA,NC,L]