簡體   English   中英

使用.htaccess文件重寫URL

[英]URL rewriting using .htaccess file

您好朋友,我正在為我的網站使用smarty,需要在我的url重寫代碼中進行一些實現,我想將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>

將此添加到您的.htaccess中

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM