Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

.htaccess - mod_rewrite RewriteRule with two / in URL is breaking, when opened once

I am facing this very annoying problem, and the solution doesn't seem to come to me.

I have made some RewriteRules in .htaccess for the urls.

So basically i am rewriting /something to index.php?page=something

RewriteRule ^([a-zA-Zа-яА-Я0-9-]+)/?$ index.php?page=$1

I have made second rule to use for pages that are dynamically generated, so i have:

RewriteRule ^page/([a-zA-Zа-яА-Я0-9-]+)/?$ index.php?page=webpage&page_url=$1

Everything works fine, until the moment that i follow one of the /page/ links, then, all links become /page/page/something ....

Also i have /category/something that goes to indes.php?page=category&category_url=someging When i am in /page/something those links become /page/category/something ...

I am sure that there is some very easy way to escape that problem, but I cannot find it ...

This is my whole .htaccess file:

   RewriteEngine On
    
    RewriteRule ^(admin|img)($|/) - [L]
    RewriteBase /auto-remote
    RewriteRule ^index.php$ - [L]
    
    
    RewriteRule ^([a-zA-Zа-яА-Я0-9-]+)/?$ index.php?page=$1
    RewriteRule ^page/([a-zA-Zа-яА-Я0-9-]+)/?$ index.php?page=webpage&page_url=$1
RewriteRule ^category/([a-zA-Zа-яА-Я0-9-]+)/?$ index.php?page=category&category_url=$1
    
    
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l
    RewriteRule ^.*$ - [L,QSA]
    RewriteRule ^.*includes/(.*)$ includes/$1 [L]
    RewriteRule ^.*media/(.*)$ media/$1 [L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...