简体   繁体   English

.htaccess代码mod-rewrite代码清理

[英].htaccess code mod-rewrite code cleaning

im kind a new in this mod rewrite thing. 我在这个mod重写的东西是一种新的东西。

im trying to do some basic redirect. 我试图做一些基本的重定向。

Options +FollowSymLinks
RewriteEngine on
ErrorDocument 404 /index.php
RewriteCond %{HTTP_HOST} ^pickndrive.info
RewriteRule (.*) http://www.pickndrive.info/$1 [R=301,L]
RewriteRule ^new/cars/([^/]+)/([^/]+)/? profiles.php?carname=$2&carnumb=$1 [L]
RewriteRule ^used/cars/([^/]+)/([^/]+)/? used.php?carname=$2&carnumb=$1 [L]
RewriteRule ^compare/([^/]+)/([^/]+)/([^/]+)/? compare.php?car[]=$1&car[]=$2&car[]=$3 [L]
RewriteRule ^compare/([^/]+)/([^/]+)/? compare.php?car[]=$1&car[]=$2 [L]
RewriteRule ^compare/([^/]+)/? compare.php?car[]=$1 [L]

thats my .htaccess but its in a very bad condition ! 多数民众赞成我的.htaccess但它的状况非常糟糕!

what im trying to do is. 我想要做的是。

1) Trying to tell google that pickndrive.info and www.pickndrive.info are the same. 1)试图告诉谷歌pickndrive.info和www.pickndrive.info是一样的。

2) redirect /new(or used)/cars/(INT value)/(string) to X.php?carname=(string)&carnumb=(INT) 2)重定向/新(或使用)/ cars /(INT值)/(字符串)到X.php?carname =(string)&carnumb =(INT)

3) redirecting /cars/(STRING) into a search page search.php?query=$1 3)重定向/ cars /(STRING)到搜索页面search.php?query = $ 1

4) redirecting /cars to browse.php?#tabs-all 4)重定向/汽车到browse.php?#tabs-all

5) redirecting compare/*/ (any amount up to 3 times) to compare.php?car[]=X1&car[]=X2&car=X3 5)将compare / * /(任意数量最多3次)重定向到compare.php?car [] = X1&car [] = X2&car = X3

well as far is this its working. 远远就是它的工作。 but i cannt get goal number 3/4 to work cause if i do they just screw the rest :(. 但我不能让目标号3/4工作,如果我这样做他们只是拧其余:(。

can some one point me out how to write a nice clean .htaccess mod-rewrite please :) 可以有人指出我如何写一个漂亮的干净.htaccess mod-rewrite请:)

Something like this for #3/4? #3/4这样的东西?

RewriteRule ^cars/([^/]+)/? search.php?query=$1 [L]
RewriteRule ^cars/? browse.php [L]

You should be able to add that at the end. 你应该能够在最后添加它。 Note that the #tabs-all isn't going to translate as a rewrite, since it's something the browser handles on the client side and nothing the server can do. 请注意, #tabs-all不会转换为重写,因为它是浏览器在客户端处理的内容,而服务器无法执行任何操作。 You could maybe add some javascript to automatically get the browser to go to #tabs-all with some javascript in browse.php. 您可以添加一些javascript来自动让浏览器转到#tabs-all,在browse.php中使用一些javascript。

I don't know if there's a cleaner way to do #5 besides the 3 "compare" rules, and #1 and #2 are fine. 除了3“比较”规则之外,我不知道是否有更简洁的方法来做#5,#1和#2都没问题。 If you rename (or symlink) "search.php" to "new.php", you could combine those 2 rules to: 如果将“search.php”重命名(或符号链接)为“new.php”,则可以将这两个规则组合为:

RewriteRule ^([^/]+)/cars/([^/]+)/([^/]+)/? $1.php?carname=$3&carnumb=$2 [L]

but I think it's better to distinctly rule out /new/cars/ and /used/cars/, since that rule would also rewrite "/qwerty/cars/" to "qwerty.php?..." 但我认为最好明确排除/ new / cars /和/ used / cars /,因为该规则也会将“/ qwerty / cars /”重写为“qwerty.php?...”

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

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