简体   繁体   English

.htaccess在$ page上重写

[英].htaccess rewrite on $page

It seems I am stuck. 看来我被困住了。 I have found answers, but I can't get them to work. 我找到了答案,但是我无法使它们起作用。

I am working on this website . 我正在这个网站上工作。 I use a switch to determine what content should be visible. 我使用开关来确定哪些内容应该可见。 I use the variable $page. 我使用变量$ page。

The links with this method are not good for SEO so I want them to be /example instead of index.php?page=example . 这种方法的链接对SEO不利,因此我希望它们成为/example而不是index.php?page=example

I have looked at all the different answers to this on StackOverflow, but I can't get any solutions to work. 我已经在StackOverflow上查看了所有不同的答案,但是我找不到任何解决方案。 There are no errors coming up and the site will show just fine, but the rewrite doesn't work. 没有出现错误,该站点将正常显示,但重写无效。

I have tried on both my servers on servage.net and one.com 我在servage.net和one.com上的服务器上都尝试过

Any suggestions? 有什么建议么? :D would be much appreciated! :D将不胜感激!

Try adding this to the .htaccess file in your web document root folder (often public_html or htdocs ), then point your browser to example.com/somepage : 尝试将其添加到Web文档根文件夹(通常是public_htmlhtdocs )的.htaccess文件中,然后将浏览器指向example.com/somepage

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^./]+)/?$ page=$1 [L,R]

Once you are satisfied that the redirect works, you can change the R to R=301 to make it permanent. 一旦确定重定向有效,就可以将R更改为R=301以使其永久不变。 This assumes that mod_rewrite is both installed and activated for htaccess files. 这假定为htaccess文件同时安装激活了mod_rewrite。 If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo(); 如果不确定,要检查是否安装了mod_rewrite,请查看phpinfo();输出中已安装模块的列表phpinfo(); By default, mod_rewrite is not enabled for htaccess files. 默认情况下,htaccess文件未启用mod_rewrite。 If you are managing your own server, open httpd.conf and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All 如果要管理自己的服务器,请打开httpd.conf并确保webroot目录块包含以下行之一: AllowOverride FileInfoAllowOverride All

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

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