I am completely nube with htaccess rewriting. Today I am stuck with a problem..
I want my url www.try.com/formal-shoes.php?catId=2 to show as www.try.com/second
second one www.try.com/formal-shoes.php?catId=1 to show as www.try.com/first Like this. Please help me to do so. what shall be rule...
As by hit and trial I wrote
<IfModule mod_rewrite.c>
RewriteRule formal-shoes.php?catId=2 second/$1 [R=301,L]
</IfModule>
You are looking at this the wrong way! Your rewrite rule should be like:
RewriteEngine on
RewriteRule ^/second$ index.php?catId=2 [QSA,L]
RewriteRule ^/first$ index.php?catId=1 [QSA,L]
Note: We are rewriting the expected url to the actual url. Also, RewriteEngine on is mandatory!
PS. Its Noob not nube :)
Related
I just learnt about url-rewrite for my website with .htacess. My actual url is:
localhost/index.php?view=some-page
So i write this RewriteRule like this:
RewriteRule ^/([^/]*)/?$ /index.php?view=$1 [NC,L]
When i typed localhost/homepage on my browser, It does not work, it displays error 404 object not found. What have i done wrong please show me.
Many thanks
This should work in your DocumentRoot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?view=$1 [QSA,L]
Leading slash is not matched in htaccess.
are you using apache?
This link from step 6 helped me
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
When i was playing around with rewrites i had to enable it and tell apache where the pages were stored
I want this: RewriteRule ^paper$ /express/index.php?c=p [L] but it does not work. Instead, it's trying to send me to /index.php?c=p, ignoring the subdirectory express altogether. However, RewriteRule ^express/paper$ /express/index.php?c=p [L] works. This is my .htaccess code:
RewriteEngine on
RewriteBase /
RewriteRule ^paper$ /express/index.php?c=p [L]
RewriteRule ^express/paper$ /express/index.php?c=p [L]
The url I WANT is just http://site.com/paper but I have to do http://site.com/express/paper to get the rewrite rule to work.
And yes, I only use one of those rewrite rules at a time.
UPDATE
Well, I'm not really getting any responses, so I'm going to go ahead and close this browser tab. I'll check back now and then but don't be offended if it takes a little while. Thanks for any help offered.
I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
RewriteRule ^(.*)$ basic.php?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/
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]
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