Why won't this regexp in htaccess work properly?

Zach

I currently use the following htaccess code to remove all php extensions and also allow the /index.php page to load without the word "index" seeing that's the cost of removing .php:

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

I used to create a new page for every single user but as one could probably see, this is not such a good idea. So i deleted all the user pages and i would include them a different way but i would need to pass the requested page as a get parameter to another file. So I decided to route every main level (/) requested page through a file in a different directory, like so:

RewriteRule ^([^/]+)$ some/page.php?requested_page=$1 [L,QSA,NC]

But it does not work with the /index.php page if someone just requested it like this: /

i changed the code to:

RewriteRule ^(<?!)([^/]+)$ some/page.php?requested_page=$1 [L,QSA,NC]

and now the "/" request works and any page that really exist works, but the "fake user pages" now dont work. is there way i can possibly do both?

Jon Lin

Try changing the regex to use * instead of +:

RewriteRule ^([^/]*)$ some/page.php?requested_page=$1 [L,QSA,NC]

Because the / request is an empty URI (the leading slash is stripped before the rules get applied).

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why won't the routing work in this code?

분류에서Dev

Why won't this MySQL stored procedure work?

분류에서Dev

Graphql Query with express and Mongodb won't work properly?

분류에서Dev

Why doesn't my javascript regexp work with array items?

분류에서Dev

Why std::basic_fstream<unsigned char> won't work?

분류에서Dev

RequestContext won't work

분류에서Dev

AJAXify won't work on phpBB?

분류에서Dev

Program won't work in FireFox

분류에서Dev

Fade in Function Won't Work

분류에서Dev

Why won't DNS resolve?

분류에서Dev

Alsamixer won't work with bluetooth device

분류에서Dev

Post variables with ajax won't work

분류에서Dev

Simple class won't work in C++

분류에서Dev

Laravel named routes won't work on wampserver

분류에서Dev

Now visudo won't work at all

분류에서Dev

The hover for my buttons and links won’t work

분류에서Dev

My update queries won't work

분류에서Dev

For /F "skip=0" won't work as expected

분류에서Dev

I'm trying to get jquery working in the background.js of my chrome extension and it won't work. why?

분류에서Dev

Vagrant won't run startup-once files properly

분류에서Dev

Skewed border won't display properly in FiFO on MacOs

분류에서Dev

Why won't jQuery remove my class?

분류에서Dev

Why Won't the BG Colors Show Up?

분류에서Dev

Why won't YouTube in Firefox prevent the screensaver?

분류에서Dev

Why won't the terminal display new lines?

분류에서Dev

Why won't dhcpd listen on the virtual interface

분류에서Dev

drawImage() doesn't work properly javascript

분류에서Dev

Can't get functions to work properly

분류에서Dev

php editing script doesn't work properly