URL Rewriting on Localhost? Apache PHP
Solution 1
You want this if your .htaccess
file is located in the site root (in the htdocs
folder):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m3/([a-zA-Z0-9-]+)$ m3/index.php?profile=com_frontpage&url=$1 [L,QSA]
Also, you need to save your file as .htaccess
. Just "Save As..." from whatever editor you're using and save the file as .htaccess
. The only place that you can't do this from is within Windows Explorer, but that's just Explorer being stupid; you definitely can save the file with the correct name from a program (even Notepad).
Or, if you prefer, you can do it from command line:
cd C:\path\to\xampp\htdocs\
rename htaccess.txt .htaccess
Solution 2
Make sure you have this option set in your document root directory in Apache's httpd.conf file:
AllowOverride All
Solution 3
Change your RewriteBase
.
RewriteEngine on
RewriteBase /m3/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)$ index.php?profile=com_frontpage&url=$1 [L,QSA]
EDIT: Fixed syntax.
Stanley Ngumo
Updated on June 04, 2022Comments
-
Stanley Ngumo almost 2 years
I am using Apache mod_rewrite on Xampp on my local machine but the code doesnt seem to work.
Please look at the code below and assist me. I'm a beginner with this.
RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^m3/([a-zA-Z0-9-]+)$/?profile=com_frontpage&url=$1 [L,QSA]
What I want is the URL below:
http://localhost/m3/?profile=com_frontpage&url=nero
to be rewritten as
http://localhost/m3/nero
Please help me achieve this.
Thanx
Thanks for your quick responses
I have implemented the revised code given but once I try to enter the new URL I keep getting a 404 error.
I am using Xampp on a Windows OS so renaming the file to .htaccess is being rejected and I am not sure using 'htaccess.txt' is working.
What could be the issue?
Thanx