简体   繁体   English

Mod_rewrite - url重写不起作用

[英]Mod_rewrite - url rewriting isn't working

I've been trying to get the mod_rewrite in my .htaccess file to work for the past few hours but I can't seem to pull it off. 我一直试图让我的.htaccess文件中的mod_rewrite在过去几个小时内工作,但我似乎无法将它拉下来。 The .htaccess files definitely work on my server because I've used them before. .htaccess文件肯定可以在我的服务器上运行,因为我之前使用过它们。

I've tried to rewrite it with this generator and testing it with this tool as well as on my server. 我试图用这个生成器重写它并使用这个工具以及我的服务器进行测试。

URL 网址

I need to turn 我需要转

http://someurl.com/news-detail.html?id=10&news=this-is-an-article http://someurl.com/news-detail.html?id=10&news=this-is-an-article

into

http://someurl.com/news/10/this-is-an-article http://someurl.com/news/10/this-is-an-article

or 要么

http://someurl.com/10/news/this-is-an-article http://someurl.com/10/news/this-is-an-article

Rewrite 改写

I've tried: 我试过了:

RewriteEngine On
RewriteRule ^([^/]*)/news/([^/]*)$ /news-detail.html?id=$1&news=$2 [L]

and

RewriteEngine on
RewriteRule /(.*)/news/(.*) news-detail.html?id=$1&news=$2 [L]

and

RewriteEngine on
RewriteRule news/([0-9]+)/([a-zA-Z_]+)$ news-detail.html?id=$1&news=$2 [L]

and many others. 和许多其他人。

I hope someone can help me out here.. 我希望有人能在这里帮助我..

Kindly check/add RewriteBase in your .htaccess file. 请在.htaccess文件中检查/添加RewriteBase。 Also check if htaccess is allowed to rewrite or not. 还要检查是否允许htaccess重写。 Syntax is below 语法如下

RewriteEngine on
RewriteBase /flodername/
RewriteRule ^urlinbrowser/(.*)/(.*)$ filename.php?first_param=$1&secondparam=$2 [L]

Keep your rules like this in root .htaccess: 在root .htaccess中保留这样的规则:

RewriteEngine On
RewriteBase /dev/hoig/

RewriteCond %{THE_REQUEST} /news-detail\.html\?id=([^\s&]+)&news=([^\s&]+) [NC]
RewriteRule ^ %1/news/%2? [R=302,L]

RewriteRule ^([^/]+)/news/([^/]+)/?$ news-detail.html?id=$1&news=$2 [L,NC,QSA]

This will support /10/news/this-is-an-article URI structure for pretty URLs. 这将支持/10/news/this-is-an-article URI结构,用于漂亮的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM