简体   繁体   English

简单的htaccess规则,用于重写URL

[英]Simple htaccess rule for rewriting the URL

Im trying to achieve this 我正在努力实现这一目标

http://domain.com?q=page-slug to http://domain.com/page-slug

right now if I access this http://domain.com?q=page-slug my webpage is working, but I want clean URls like http://domain.com/page-slug 现在,如果我访问此http://domain.com?q=page-slug我的网页就可以正常工作,但是我想要干净的URls,例如http://domain.com/page-slug

I used this code in my htaccess but returning 500 error 我在htaccess中使用了此代码,但返回500错误

RewriteEngine On

RewriteRule ^(.*)$ ?q=$1 [L,QSA]

any help please. 请任何帮助。

Try this I am assuming you have index.php page which is handling the request. 试试这个,我假设您有正在处理请求的index.php页面。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)$ index.php?q=$1 [QSA,L]

If not index.php change to actual page you have. 如果不是index.php更改为您拥有的实际页面。

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

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