Mobile app version of vmapp.org
Login or Join
Ogunnowo487

: Url rewrite not work in wamp localhost I am developing a PHP web application. I have pages, posts, categories, product and etc. Here is my .htaccess file to create SEO friendly URL: Options

@Ogunnowo487

Posted in: #Htaccess #Php #Seo

I am developing a PHP web application. I have pages, posts, categories, product and etc.

Here is my .htaccess file to create SEO friendly URL:

Options -Indexes
RewriteEngine on
RewriteRule ^Page/(.*)/(.*)$ Page.php?Page_Id=&Page_Title= [NC,L]
RewriteRule ^Product/(.*)/(.*)$ Product.php?Product_Id=&Product_Title= [NC,L]
RewriteRule ^Category/(.*)/(.*)$ Category.php?Category_Id=&Category_Title= [NC,L]
RewriteRule ^Single/(.*)/(.*)$ Single.php?Post_Id=&Post_Title= [NC,L]
RewriteRule ^Blog/(.*)/(.*)$ Blog.php?Category_Id=&Category_Title= [NC,L]

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


<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>


When I visit Page.php?Page_Id=13 it works. And also when I visit Page/13/Page-Title it works. Everything is good when I test my application on the server, but it doesn't work in wamp localhost.

I active

LoadModule rewrite_module modules/mod_rewrite.so


in Apache http.conf and here is my vhost:

<VirtualHost *:8080>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>


<VirtualHost *:8080>
ServerName schoolarshop
DocumentRoot "c:/wamp64/www/schoolarshop"
<Directory "c:/wamp64/www/schoolarshop/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride none
Require local
</Directory>
</VirtualHost>


Example of error in localhost is:

Notice: Undefined index: Page_Id in Page.php on line 8


Why does it work on the server and not in localhost?

I Googled a lot but it can't find anything.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Ogunnowo487

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

Options +Indexes +Includes +FollowSymLinks +MultiViews



Why are you explicitly enabling MultiViews in your server config? This is likely the cause of your problem. Try removing +MultiViews from your server config (above), and/or disable MultiViews at the top of your .htaccess:

Options -Indexes -MultiViews




MutliViews is disabled on a default Apache install, however, some (shared) hosts do seem to enable it. So, disabling it in .htaccess as a matter of course is probably recommended.

(But also, why are you enabling Includes - is this really necessary? Since you are using PHP, this is unlikely.)

The effect of MultiViews is noticeable because you have effectively removed the file extension to create your user-friendly URLs.

With MultiViews enabled (part of mod_negotiation)... when you request Page/13/Page-Title, Apache tries to find a matching file in the current/root directory that matches the basename Page, by trying various extensions that would return the appropriate mime-type. This occurs before mod_rewrite is able to rewrite your friendly URL. So, MultiViews ends up rewriting your request to Page.php without passing any of the URL params (the rest of the URL will likely be seen as PATH_INFO), hence your "Undefined index" PHP notice.

(Although you should also be checking for the existence of this $_GET variable in your PHP script, which you don't seem to be doing.)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme