【问题标题】:URL rewriting using .htaccess file使用 .htaccess 文件重写 URL
【发布时间】:2017-04-08 20:13:02
【问题描述】:

你好朋友,我正在为我的网站使用 smarty,并且需要在我的 url 重写代码中进行一些实现, 我想从http://example.com/apple/iphone-7-123.html重写网址 到http://example.com/iphone-7-123.html 我的 .htaccess 文件中有这些代码用于 url 重写

RewriteEngine On
Options +FollowSymLinks
Options -Indexes
Options -MultiViews

RewriteBase /
RewriteRule ^login - [L,NC]
RewriteRule ^(core/install/tables.sql) - [F,L,NC]

RewriteRule ^contact\.html$ /contact.php [L]
RewriteRule ^compare\.html$ /compare.php [L]
RewriteRule ^([^/]*)\.html$ /page.php?permalink=$1 [L]

RewriteRule ^search/([^/]*)$ /search.php?search=$1 [L]

RewriteRule ^([^/]*)/$ /categ.php?section_permalink=$1 [L,NC,QSA]
RewriteRule ^([^/]*)/page-([0-9]+)$ /categ.php?section_permalink=$1&pagenum=$2 [L,NC,QSA]

RewriteRule ^([^/]*)/([^/]*)/$ /categ.php?section_permalink=$1&categ_permalink=$2 [L,NC,QSA]
RewriteRule ^([^/]*)/([^/]*)/page-([0-9]+)$ /categ.php?section_permalink=$1&categ_permalink=$2&pagenum=$3 [L,NC,QSA]

RewriteRule ^([^/]*)/([0-9]+)-([^/]*)/$ /categ.php?section_permalink=$1&subcateg_id=$2&subcateg_permalink=$3 [L,NC,QSA]
RewriteRule ^([^/]*)/([0-9]+)-([^/]*)/page-([0-9]+)$ /categ.php?section_permalink=$1&subcateg_id=$2&subcateg_permalink=$3&pagenum=$4 [L,NC,QSA]

RewriteRule ^([^/]*)/([^_]*)-([0-9]+)\.html$ /post.php?categ_permalink=$1&permalink=$2&id=$3 [L]
RewriteRule ^([^/]*)/([^_]*)-([0-9]+)-prices\.html$ /post-prices.php?categ_permalink=$1&permalink=$2&id=$3 [L]
RewriteRule ^([^/]*)/([^_]*)-([0-9]+)-opinions\.html$ /post-opinions.php?categ_permalink=$1&permalink=$2&id=$3 [L]
RewriteRule ^([^/]*)/([^_]*)-([0-9]+)-media\.html$ /post-media.php?categ_permalink=$1&permalink=$2&id=$3 [L]

RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]





<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>

<IfModule pagespeed_module>
ModPagespeed off
# using commands,filters etc
</IfModule>

【问题讨论】:

    标签: php html .htaccess


    【解决方案1】:

    将此添加到您的 .htaccess 中

    RewriteRule ^apple/iphone-7-123.html/$   iphone-7-123.html [NC,L]
    

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 2013-04-22
      • 1970-01-01
      • 2014-03-24
      • 1970-01-01
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多