mod-rewrite remove folder name from url

不打扰是莪最后的温柔 提交于 2019-12-19 07:18:12

问题


I am using OJS and I have installed it inside a folder called "journals". I have created some journals there (for example "journal1", "journal2", etc).

Now I am getting paths like this: www.example.com/journals/index.php/journal1, www.example.com/journals/index.php/journal2, etc.

What I want is to map www.example.com/journals/index.php/journal1 to looks like www.example.com/index.php/journal1 (removing the journal part from URL).

I can't move OJS to root because I have some other files there.

Here is the .htaccess file which I am using currently (it's in "journals" folder and giving me a 500)

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^journals
RewriteRule ^(.*) /journals/$1 [L]
</IfModule>

Also Here is the error.log

[Fri Oct 12 22:16:45 2012] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. 

回答1:


When you put those rules inside the htaccess file in your /journals directory, it's causing a rewrite loop. $1 never starts with journals because you're inside the journals directory, thus the rule keeps getting applied.

You'll need to put something like this in your htaccess file in your site-root, the / directory:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/journals
RewriteRule ^index\.php(.*)$ /journals/index.php$1 [L]


来源:https://stackoverflow.com/questions/12862809/mod-rewrite-remove-folder-name-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!