doomm4711 2015-10-27 07:59
浏览 48

htaccess重写链接并复制它

I have this htaccess code

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^einfogarden.com$
RewriteRule (.*) http://www.einfogarden.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/+single\.php\?title=([^\s&]+) [NC]
RewriteRule ^ %1/? [R=302,L,NE]

## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \s/+(.*?)[^/][?\s]
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=302]

# convert %20 to -
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [L,NE]
RewriteRule "^(\S*) (\S*)$" $1-$2 [L,R=302,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ single.php?title=$1 [NE,L,QSA]

which should remove single.php?title= from url and replace the 20% by slash and it work corrctly. but i have 2 problem 1. it stop the css in my website 2. if you try to click any link (except) the home page it will give you something like this http://www.einfogarden.com/%D9%81%D9%88%D8%A7%D8%A6%D8%AF-%D8%A7%D9%84%D8%AC%D8%B1%D8%AC%D9%8A%D8%B1/single.php?title=%D9%81%D9%88%D8%A7%D8%A6%D8%AF%20%D8%A7%D9%84%D8%B1%D9%85%D8%A7%D9%86%20%D8%A7%D9%84%D8%B1%D8%A7%D8%A6%D8%B9%D8%A9 it duplicate the link

  • 写回答

1条回答 默认 最新

  • doubiaokai4998 2015-10-27 08:16
    关注

    You are asking in the .htaccess the url of your current page. So yourwebsite.com/home will be yourwebsite.com/home/home I edited your code a little. using this will do fine.

    RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -d [NC]
    RewriteRule ^(.*?)$ $1 [L] 
    RewriteCond %{REQUEST_URI} !^/cache
    RewriteCond %{REQUEST_URI} !^/images
    RewriteCond %{REQUEST_URI} !.*\.(css|jpg|gif|zip|js)
    
    RewriteRule ^(.*)/(.*)/?$ index.php?page1=$1&page2=$2 [L]
    RewriteRule ^(.*) index.php?page1=$1 [L] 
    #RewriteRule ^(.*)/?$ http://www.google.com/ [R]
    

    This is a easy way the use SEO url's The RewriteRule is for creating a new var to your url.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么