【问题标题】:Htaccess mod rewrite seo url setupHtaccess mod 重写 seo url 设置
【发布时间】:2019-04-23 16:53:50
【问题描述】:

我有一个网站在没有 seo 的情况下运行,我更改了指向 seo url 的链接。 我创建 seo 链接并将它们保存在数据库中。 usaqe 是:seo_url,php 部分一切正常,但 htaccess 设置有问题。 我阅读了大量关于 htaccess 设置的文章和问题,毕竟我找到了这个无法正常工作的解决方案。

在 Upanel 分页部分需要一些帮助。 Upanel 是一个文件夹。

closest answer was that one :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^home/?$ index.php [NC,L]

RewriteRule ^contact/?$ contact.php [NC,L]

RewriteRule ^Upanel/?$ Upanel/account.php [NC,L]

RewriteRule ^Upanel/page/?$ Upanel/account.php?page=$1[L]

RewriteRule ^reset-password/?$ forgot.php [NC,L]

RewriteRule ^change-password/?$ resetpass.php [NC,L]

RewriteRule ^user/?$ login.php [NC,L]

RewriteRule ^search/?$ search.php [NC,L]

RewriteRule ^hr-search/?$ ik.php [NC,L] 

RewriteRule ^sitemap/?$ rss.php [NC,L]

RewriteRule ^([a-zA-Z0-9_-]+)/?$ detail.php?p=$1 [NC,L]

RewriteRule ^category/([a-zA-Z0-9_-]+)/?$ categories.php?q=$1 [NC,L] 

感谢帮助

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    对于您列出的所有规则,不需要重写条件 (RewriteCond)。

    阅读下面示例中的 cmets。

    RewriteEngine On
    # ^home index.php :request "starts with home"(^home) redirected to index.php,
    # [NC,L] search is case insensitive(ie it also matches Home,hOme etc.
    # [L] stop processing after this rule.
    RewriteRule ^home index.php [NC, L]
    # ^Upanel/page/ request starts with Upanel/page/ 
    # (.*)$  "everything"(.*) after it "upto end"($) is stored in $1
    RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]
    

    刚刚修改了你的规则。

    RewriteEngine On
    
    RewriteRule ^home/ index.php [NC,L]
    RewriteRule ^contact/ contact.php [NC,L]
    RewriteRule ^Upanel/$ Upanel/account.php [NC,L]
    RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]
    RewriteRule ^reset-password/ forgot.php [NC,L]
    RewriteRule ^change-password/ resetpass.php [NC,L]
    RewriteRule ^user/$ login.php [NC,L]
    RewriteRule ^search/$ search.php [NC,L]
    RewriteRule ^hr-search/$ ik.php [NC,L] 
    RewriteRule ^sitemap/$ rss.php [NC,L]
    RewriteRule ^([a-zA-Z0-9_-]+)/ detail.php?p=$1 [NC,L]
    RewriteRule ^category/([a-zA-Z0-9_-]+) categories.php?q=$1 [NC,L]
    

    看这个。

    RewriteRule ^Upanel/ Upanel/account.php [NC,L]
    RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]
    

    这里第二个 rewriteRule 永远不会起作用,因为每个匹配第二个条件的请求也匹配第一个条件和 L 标志确保它在第一个条件处停止。以下任何一种都可以,请根据您的要求进行选择。

    RewriteRule ^Upanel/$ Upanel/account.php [NC,L]
    RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]
    

    RewriteRule ^Upanel/page/(.*)$ Upanel/account.php?page=$1 [L]
    RewriteRule ^Upanel/ Upanel/account.php [NC,L]
    

    请参阅rewrite rule flagsorder of rewrite rules 的答案

    【讨论】:

    • 首先感谢您的回答,我尝试了您修改后的代码,但出现错误 * 在此服务器上找不到请求的文件*。在除 detail.php 之外的所有网址上,我正在阅读您的帖子并尝试组合
    • 在仔细阅读您的 cmets 后成功了,非常感谢您,不能给您声誉,但很抱歉。
    猜你喜欢
    • 2015-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 2013-11-06
    相关资源
    最近更新 更多