htaccess code not working when i move my files in subfolder

谁说我不能喝 提交于 2020-01-06 04:49:27

问题


I am trying to move my project files from the root folder to subfolder.

Now all files are in subfolder.

I have this following htaccess code:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /project/

ErrorDocument 404 http://localhost/404.php 
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^profile/([\w-]+)/?$ /profile.php?username=$1 [L,QSA] 
RewriteRule ^profile/(followers|following)/([\w-]+)/?$ $1.php?username=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

I must be change the RewriteBase / like this RewriteBase /project/ because of i moved php files in subfolder (project) . So after moved the files and changed the RewriteBase then the following code is not working

RewriteRule ^profile/([\w-]+)/?$ /profile.php?username=$1 [L,QSA]

So i get this error :

Not Found The requested URL /profile.php was not found on this server.

The url is like this: http://localhost/project/profile/john

What i am missing here anyone can help me in this regard please ?

Note: I have move the htaccess file in project folder.

If i try to open the url without the fake folder (profile) like this:

http://localhost/project/profile?username=john then the page is opening without error.

The url normalize this:

http://localhost/project/profile/john

because of this rule:RewriteRule ^profile/([\w-]+)/?$ /profile.php?username=$1 [L,QSA]

but it is giving Not Found The requested URL /profile.php was not found on this server.


回答1:


The @marcello-mönkemeyer comment is right. You just need to remove slash like this:

RewriteRule ^profile/([\w-]+)/?$ profile.php?username=$1 [L,QSA]
                                ^
remove the slash / from here ---|---


来源:https://stackoverflow.com/questions/52017924/htaccess-code-not-working-when-i-move-my-files-in-subfolder

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