3

I have tried a ton of solutions posted at stackoverflow but nothing seems to work for me. I would like to rewrite a few URLs on my site to be search engine friendly.

I would like a URL like this:- http://www.mysite.com/index.php?filter=accounts To display as:- http://www.mysite.com/accounts

A lot of posts around the web give this as the solution:-

RewriteRule ^([^/]+)/?$ index.php?filter=$1 [QSA,L]

But this doesn't do anything.

My site is a Joomla CMS site and there are already some rewrites within the .htaccess file. Could it be that I am putting my new RewriteRule is the wrong place?

Here is the full .htaccess file without my new RewriteRule added

Options +FollowSymLinks
RewriteEngine On

# prevents people from accessing anything with phpMyAdmin
RewriteRule phpMyAdmin - [F]

# force canonical www if request is for non-www or has port number etc
RewriteCond %{HTTP_HOST} !^(www\.mysite\.com)?$
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteBase /
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Any help would be much appreciated. :-)

1 Answer 1

3

UPDATED

Now is tested. Try this:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9-=_?]+)/?$ index.php?filter=$1 [L] 

.htaccess goes in root directory.

The requested URL is http://www.mysite.com/accounts/ but could be anything: http://www.mysite.com/apples/.

NOTE: The URL displayed in the address bar is the one that was entered in that address bar. I assume is not http://www.mysite.com/index.php?filter=accounts because I guess the purpose of the redirection is to replace it with a more friendly one (http://www.mysite.com/accounts), which is the one that has to be typed in the address bar, not the other way around. Little confusing but I hope it makes sense.

To test it, include the following only code at index.php in root directory.

<?php 

if ($_GET['filter'] == 'accounts') {
echo "This is Accounts<br /><br />";    
}else {
echo "This is INDEX<br /><br />";       
}

?>

As to where to place the rewrite rules inside .htaccess, I could not know. I guess you have to try it before and after the actual rules.

Sign up to request clarification or add additional context in comments.

6 Comments

Hi,Thanks for your reply. Unfortunately it doesn't do anything. The query string could be one of several options and won't always be 'accounts' although if I get a solution to work for a single query there aren't that many that I couldn't add a line for each one.
Well, I will try and TEST a similar solution. There is one, I am sure. It is important the .htaccess file is in root directory: public_html in this case.
Hi. The .htaccess is in the public_html and I have just cleared caches just to make sure that there isn't a caching issue stopping it working.
Hi Felipe. I really appreciate your efforts trying to help me out but I still can't get this to work. I wonder if what you have suggested is the opposite of what in need to happen. I need the requested URL to be mysite.com/index.php?filter=accounts so that I can use the query string in PHP but I would like the URL that is displayed in the browser address bar to read mysite.com/accounts or if that isn't possible the it could be mysite.com/services/accounts or mysite.com/services/applies, etc. Thanks again.
Thanks Felipe. Got there in the end. Really appreciate your help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.