![](/img/trans.png)
[英]htaccess url rewrite if file doesn't exist *OR* specific directory
[英]Rewrite URL doesn't work in .htaccess file
我有问题使用.htaccess来重写一些友好的URL。
根URL是http://www.example.com/my/
工作电话网址是http://www.example.com/my/Post.php?id=2
.htaccess文件和Post.php都位于子目录http://www.example.com/my/
但我希望它如下: http : //www.example.com/my/job/kuantan/?id = 2
.htaccess配置如下:
DirectoryIndex index.php
Options All -Indexes
#ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^job/kuantan/([0-9]+) /Post.php?id=$1 [L,QSA, NC]
但是,一旦我部署了上述.htaccess配置文件,它也会提示500内部错误消息。
.htaccess配置中是否缺少或错误? 如果有人可以伸出援助之手,请提出意见并表示非常感谢。 谢谢。
您可以在/my/.htaccess
使用此代码:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /my/
RewriteCond %{THE_REQUEST} /Post\.php [NC]
RewriteRule ^ job/kuantan [R=302,L,NE]
RewriteRule ^job/kuantan/?$ Post.php [L,NC]
查询字符串会自动转移,因此无需在规则中捕获它。
你应该只需要一个规则:
RewriteRule ^/my/job/kuantan/$ /my/Post.php
查询字符串默认是转义的。
假设.htaccess和Post.php位于子目录/my/
:
DirectoryIndex index.php
Options All -Indexes
#ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^job/kuantan/([0-9]+)$ Post.php?id=$1 [L,QSA,NC]
删除[]
之间的所有空格。 更改/Post.php?id=1
到Post.php?id=$1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.