简体   繁体   中英

Rewrite Rule don't let me access my domain's index.php

In my page, when I write the url domain.com/abc it uses the htaccess RewriteRule ( posted below) and opens the company-profile.php page, showing the ABC profile. ABC IS AN EXAMPLE. IT MAY BE ANYTHING

However, even I have a domain.com/index.php file, when I write just domain.com and hit enter, it takes me to the company-profile.php page where it supposed to show the index.php file

My question is how can I fix this ?

RewriteEngine On
RewriteRule ^([a-z0-9]+)?$ /domain.com/company-profile.php?cid=$1 [NC,L]

The first part of your RewriteRule is matching anything that's a combination of letters and numbers and passing it to your /domain.com/profile/company-profile.php script. You need to be more specific on your RewriteRule , ie:

RewriteEngine On
RewriteRule ^/profile/([a-z0-9]+)?$ /domain.com/profile/company-profile.php?cid=$1 [NC,L]

The above will only match requests beginning with /profile/ , so for example /profile/martinbean will be matched.

Something like this maybe?

RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.(php|html?)
RewriteRule ^(.*)$ profile/company-profile.php?cid=$1 [NC,L]

Is apache your web server. If the answer is yes, You should first check your loaded apache modules to see if the rewrite module is loaded. If not , then try to add this line:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

to your apache config files . Then try to restart your web server to check if the rewirte rules worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM