douzi3756
douzi3756
采纳率100%
2014-10-18 18:10

Mod_Rewrite on但不更改URL布局

Hello I've got a problem with rewriting my URLs via .htaccess

Php Info: Server API CGI/FastCGI Hoster settings: Apache mod_rewrite ON

Current url Layout:

http://www.xxxx.at/beitrag.php?thema=Bitcoins%20fuer%20jedermann%20gratis

Wanted:

http://www.xxxx.at/beitrag/Bitcoins%20fuer%20jedermann%20gratis (can I change %20 to "-" maybe too?)

I've stup a .htacces which looks like:

RewriteEngine On
RewriteRule (.*)_(.*)\.html$ /bitcoins.php?to=$1 [qsappend,L]

But the URL still looks the same, there is nothing changed.

Can someone help me please? regards

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dousi1097 dousi1097 7年前

    Try:

    Options -Multiviews
    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /+beitrag\.php\?thema=([^&\ ]+)
    RewriteRule ^ /beitrag/%1 [L,R]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^bietrag/(.+)$ /bietrag.php?thema=$1 [L]
    
    1. Turn off Multiviews so that /beitrag doesn't preemptively get served with /beitrag.php
    2. The first rule matches the HTTP request line, gruops the query string, and redirects the browser so that the new URL shows up in the location bar
    3. The second rule matches the new URL and internally rewrites it back to the one with the query string.
    点赞 评论 复制链接分享

为你推荐