简体   繁体   English

htaccess slug 404错误

[英]htaccess slug 404 error

I am creating a php website where pages are linked by slug (Ex. mysqite.com/slug). 我正在创建一个php网站,其中页面通过Slug链接(例如mysqite.com/slug)。

For slugs like ' home ', ' about-us ', ' contact ', ' my-result ' etc it's working fine but for some slugs like ' result ', ' about ' a 404 (not found) error displayed. 对于诸如“ home ”,“ about-us ”,“ contact ”,“ my-result ”等之类的标签,它工作正常,但对于诸如“ result ”,“ 关于 ”之类的某些符号,则显示404(未找到)错误。 How I resolve this issue? 我该如何解决这个问题?

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /institution/http/
RewriteRule departments(|[a-zA-Z0-9_\-/]+)$ department.php?page=$1
RewriteRule stream/(|[a-zA-Z0-9_\-/]+)$ post.php?page=$1
RewriteRule faculty/([a-zA-Z0-9_\-/]+)$ new_post.php?page=$1
RewriteRule ^([a-zA-Z0-9\-\/]+)$ index.php?page=$1

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule .* $0.php [L]
</IfModule>

You fix this in your CMS, so that you either redirect to the correct slug or create pages for "result" and "about". 您可以在CMS中解决此问题,以便您重定向到正确的子段或为“结果”和“关于”创建页面。 Otherwise you can do this right in your htaccess file: 否则,您可以在htaccess文件中执行此操作:

Add this right below RewriteEngine On : RewriteEngine On下面添加此权限:

RewriteRule ^about$ /about-us [L,R=301]
RewriteRule ^result$ /my-result [L,R=301]

You may have about.php and result.php files already existing in the same directory. 您可能已经在同一目录中存在about.phpresult.php文件。 The slug(s) match the file name(s). 该段与文件名匹配。 If so, please try: 如果是这样,请尝试:

Edit your first line to: 将第一行编辑为:

Options +FollowSymLinks -MultiViews

Remove the line: 删除行:

RewriteRule .* $0.php [L]

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

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