views:

46

answers:

2

Hi,

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

+1  A: 

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.

Martin Bean
I have changed the code I have but I am still getting a 404 error what could be the issue.
Stanley Ngumo
I've edited my above sample as I realised there was no space in your `RewriteRule`, meaning a pattern was not being matched. Try the above now.
Martin Bean
Thanx for that I didnt know about the spacing issue
Stanley Ngumo
A: 

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
Tim Stone