ht access mod_rewrite query string append flag - .htaccess

I'm using these two lines in my htaccess to direct /something to /page.php?page=something. I'd like /something?key=value to translate to /page.php?page=something&key=value.
These lines do not seem to be working.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)/$ /$1 [R,QSA]
RewriteRule ^([a-zA-Z0-9]+)$ /page.php?page=$1 [L,QSA]
Any ideas on how to improve this?

I've fixed the problem. It actually wasn't working because of another rule in the htaccess file which wasn't written correctly. The code above works fine. Thanks.

Related

What is wrong htaccess

I have the following htaccess rules but I dont know how to make it work:
RewriteEngine on
RewriteRule ^game/([^/]*)$ index.php?cash=$1
The following is the screen shot of my folders structure:
Can someone tell me how to get it to work? I have also tried:
RewriteRule ^index.php([^/]*)$ index.php?cash=$1
The URL that I want to display is: http://localhost/biteep/game/100 while the URL that I want the browser to go to is http://localhost/biteep/game?cash=100
Try to put a rewrite base into your .htaccess:
RewriteBase /biteep/
And this route should be enough:
RewriteRule ^game\/(\d+)$ index.php?cash=$1
So it works when I do this
RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?cash=$1

Using .htaccess and mod_rewrite

I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
Rewrit­eRule ^(.*)$ basic.p­hp?­url=$1 [L]
Above is what I'm currently using. However, I have no idea what I'm doing to be honest as I'm just cycling through the internet trying to figure this out.
Basically, for my website, if you type in
www.domain.com/folder/xxx/
I want it to basically be www.domain.com/folder/basic.php?url=xxx.
For some reason, all that does is cause a 404 error :/
So can someone please politely point me in the right direction?
Ok, I will explain using your htaccess.
RewriteEngine on
Turn on the Rewrite Module to enable URL rewriting
RewriteBase /folder
Rewrite the Base Directory to directory name folder
RewriteRule ^folder/(.*)$ basic.php?url=$1 [L]
Remap every request make using the folder/***** to basic.php?url=********
Note: RewriteEngine On Should be the first statement on your case
RewriteEngine on
RewriteBase /
RewriteRule ^folder/(.*)$ folder/basic.php?url=$1 [L]
This is more of a problem with regexs than .htaccess files.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://www.regular-expressions.info/

Mod_Rewrite RewriteRule issue

I have a domain at example.com
There is a subdirectory that has a quiz on it, located at example.com/quiz/?id=1
I need to change the ?id=1 to TakeTheQuiz so it would look like example.com/quiz/TakeTheQuiz
Here is what my .htaccess looks like right now (the .htaccess is located in the root direct at example.com). Right now I always get a server 500 error.
RewriteEngine On
RewriteBase /quiz
RewriteRule ^?id=1$ TaketheQuiz
This is really simple and all of the examples I have seen have been really complicated and hard for me to apply it to this one :( Help, anyone? Thank you for your time.
You've just got the rule the wrong way round:
RewriteEngine On
RewriteBase /quiz
RewriteRule ^TaketheQuiz$ ?id=1 [L]
EDIT
Per your comment try this instead:
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^$ TaketheQuiz [R=301,L]

Htaccess Rewrite second rule not working

I want to rewrite urls like index.php?c=4 & index.php?g=23 into website.com/games/categoryname/id/
and the same thing for the game page website.com/play/gamename/id/
my htaccess file looks like this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9\-_%]+)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?c=$3
RewriteRule ^([a-zA-Z0-9\-_%]+)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?g=$3
The problem is that only the first rewrite rule is working, if I comment it, then the second will work too, but never both :(. I'm testing this on MAMP
Can you please help me?
They cannot work both as they have the same condition - you have set two different actions with the same criteria and only the first one is executed.
Ah, I understood what you are trying to achieve:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(games)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?c=$3 [L]
RewriteRule ^(play)/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?g=$3 [L]
You have to do something like this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^play/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?c=$2
RewriteRule ^games/([a-zA-Z0-9\-_%]+)/([0-9]+)/$ index.php?g=$2

URL rewrite using mod_rewrite in .htaccess

I am trying to rewrite the URL using the mod_rewrite apache module.
I am trying to use it as below :
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/testing.htm wants.php?wantid=$1 [L]
I have created a .htaccess file in the directory from where the files are accessed.
The mod_rewrite is also enabled.
With all these done, i still haven't been able to get it working.
Can someone please help me with this? Please let me know if i am missing something
Thanks in Advance,
Gnanesh
As per OP's comment:
The URL shows
mydomain.com/wants.php?wantid=123. I
need to make it look like
mydomain.com/wants/123
This should work for your case:
RewriteEngine on
RewriteBase /
RewriteRule ^wants/([0-9]+)$ /wants.php?wantid=$1 [L]
It will allow you to use http://yoursite.com/wants/123 and will silently rewrite it to wants.php?wantid=123
I think a leading slash (or rather the lack thereof) might be yoru problem:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/testing.htm /wants.php?wantid=$1 [L]
Otherwise Apache might be looking for the PHP file in /wants/wants.php as it'll be treating it as a relative URL.
Hmm, so I gave it some thought and I guess you could do something like this ( only changed the regexp according to your comment, if I understood correctly ):
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/\d+$ /wants.php?wantid=$1 [L]
But I guess you could also leave out the $1 reference, and still be able to access the id in your wants.php. So
RewriteRule ^wants/\d+$ /wants.php [L]
should work too, and you can then use something like
<?php
$request = split('/', $_SERVER["REQUEST_URI"])[1];
?>
in your wants.php where the last element of the array would be your id ( or anything else you ever decide to rewrite and send to the script ).
If you want to use the rule in the .htaccess file in your wants directory, you have to strip the contextual wants/ from the start of the pattern. So just:
RewriteEngine on
RewriteRule ^([0-9]+)$ /wants.php?wantid=$1 [L]
Otherwise, if you want to use the rule in the .htaccess file in your root directory:
RewriteEngine on
RewriteRule ^wants/([0-9]+)$ wants.php?wantid=$1 [L]

Resources