【问题标题】:Search Engine Friendly URL with .htaccess in xampp windows 10 on 64-bit64位xampp windows 10中带有.htaccess的搜索引擎友好URL
【发布时间】:2016-02-16 02:58:07
【问题描述】:

我想将我的网址更改为对搜索引擎友好。我在 64 位的 Windows 10 上使用 xampp 3.2.1 我的网址如下所示:

http://smc.edu.pk/app/site/?p=12&m=c&u=Swat_Medical_College-_The_Project_of_Swat_Medical_Complex

我想让它变成这样:

http://smc.edu.pk/app/site/12/c/Swat_Medical_College-_The_Project_of_Swat_Medical_Complex.html

我已经使用 .htaccess 测试了以下代码

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/app/site/(\d+)/([a-z-]+)/(.+)\.html$ /?p=$1&m=$2&u=$3 [NC,L]

但是当我使用上面提到的第二个 url 时它返回以下错误:

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

smc.edu.pk
Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8

【问题讨论】:

    标签: php apache .htaccess seo xampp


    【解决方案1】:

    是的,我找到了解决方案:

    RewriteEngine On
    RewriteBase /app/site/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
    

    我已将 RewriteRule 更改为:

    RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
    

    并且还将 RewriteBase /app/site/ 放在第二行。 现在它工作完美....

    【讨论】:

      【解决方案2】:

      我认为应该是这样的(未测试):

      RewriteRule ^/app/site/(\d+)/([a-z-]+)/(.+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
      

      编辑:它应该是这样的(经过测试和工作):

      RewriteRule ^app/site/(\d+)/([a-z-]+)/(.+)\.html$ /app/site/?p=$1&m=$2&u=$3 [NC,L]
      

      【讨论】:

      • 亲爱的@SomeHelpingDude,它仍然显示相同的错误消息。
      • 你能告诉我们你得到的确切错误吗?您可以在 apache 日志中找到它
      • 127.0.0.1 - - [14/Nov/2015:22:51:52 +0500] "GET /app/site/12/c/Swat_Medical_College-_The_Project_of_Swat_Medical_Complex HTTP/1.1" 404 1054 "- " "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36"
      • 是的,我试过了,但还是不行,同样的错误
      • 请查看我现在正在运行的已完成的.httaccess 文件代码:
      猜你喜欢
      • 2021-06-12
      • 2012-06-18
      • 2012-03-18
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-31
      • 1970-01-01
      相关资源
      最近更新 更多