.htaccess - url RewriteEngine 未按预期工作
问题描述
我正在尝试转换:
http://localhost/mysite/blog.php?slug=post-by-paritosh
至 :
http://localhost/mysite/blog/post-by-paritosh
为此,我使用具有以下规则的 .htaccess 文件
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?blog/(.*?)/?$ /blog.php?slug=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blog\.php\?slug=([^\&\ ]+)
RewriteRule ^/?blog\.php$ /blog/%1? [L,R=301]
在http://www.htaccesscheck.com/检查语法后,我发现它没问题,但重写没有按预期工作。
解决方案
你可以试试这个 .htaccess 里面的tgconnectmediaservice/
目录:
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(tgconnectmediaservice/blog)\.php\?slug=([^&\s]+)\s [NC]
RewriteRule ^ /%1/%2? [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?blog/([^/]+)/?$ blog.php?slug=$1 [L,QSA,NC]
推荐阅读
- postgresql - 执行 Introspect 数据库时遇到 PyCharm 错误
- json - 将 Json 和普通列与 Pyspark 相结合
- python - 如何从字典创建元组?
- javascript - 在Datatable中将数据导出到excel时如何添加行?
- python-3.x - Tensorflow:InvalidArgumentError 输入和过滤器必须具有相同的深度:8 vs 1
- sql - Oracle SQL REGEXP 用不同的列值替换特定字符串
- logic - 请解释输出的逻辑
- css - 网页不会使用 Pug/W3.CSS 滚动
- java - 如何使用 Jaxb2Marshaller 从 xml 中获取嵌套元素
- flutter - 错误:无法将参数类型“FirebaseApp”分配给参数类型“Firebase”