开发者

Add directory in the middle of a URL with hataccess

My current .htacces file looks like this:

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

What I am trying to accomplish (as well as the above) is to change a url such as http://domain.com/pages/pagename to something like http://domain.com/index.php/pages/view/pagename.

Keeping in mind that I still require urls without the /page/ part such as http://domain.com/search to go to http://domain.com/index.php/search. I am working with CodeIgniter.

What I have come up with so far is:

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
Rewr开发者_StackOverflowiteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

RewriteCond %{REQUEST_URI} ^/pages/(.*)
RewriteRule ^(.*)$ ./index.php/pages/index/$1 [L,QSA]

But it isn't working.


Try this one:

RewriteEngine on

# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

# /pages/ specific rule
RewriteRule ^pages/(.*)$ index.php/pages/index/$1 [L]
# everything else
RewriteRule ^(.*)$ index.php/$1 [L]

The above assumes that http://domain.com/pages/ is not a real folder.


RewriteRule ^pages/(.*) /index.php/pages/index/$1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜