.HTACCESS Rewriting Issue - .htaccess

Can any check given code of .htaccess file and let me know what's wrong with it and why it's not working?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^itinerary/([a-zA-Z0-9_-]+)/([0-9]+)\$ itinerary-details.php?tId=$2
I want to rewrite url as below:
www.domain.com/itinerary-details.php?tId=2&tName=agra-delhi-tour
to
www.domain.com/itinerary/2/agra-delhi-tour
and
www.domain.com/itinerary-details.php?page=1&tId=2&tName=agra-delhi-tour
to
www.domain.com/itinerary/2/agra-delhi-tour/1
Please help me in doing this.
Thanks

Seems that you have the two sections in your regex reversed. This should work for both your cases:
^itinerary/([0-9]+)/([a-zA-Z0-9_-]+)/?(.*) itinerary-details.php?tId=$1&tName=$2&page=$3
I also just noticed that you were escaping the $ which would also cause problems.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^itinerary/([^/]+)/([^/]+)/?$ /itinerary-details.php?tId=$1&tName=$2 [L,QSA,NC]
RewriteRule ^itinerary/([^/]+)/([^/]+)/([^/]+)/?$ /itinerary-details.php?page=$3&tId=$1&tName=$2 [L,QSA,NC]

Related

How to rewrite the base URL?

I need to make a rewrite rule that if anyone writes website url (the main one),
www.domain.com
it will show
www.domain.com/1
But if someone looks for anything else, for example:
www.domain.com/2
it will show the requested url,
www.domain.com/2
I need only to rewrite the base root /.
Thank you for your help,
Adam :)
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ /1 [L]

Change URL but stay on the same page using htaccess

I have a URL:
www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space
I want to stay on the same page above but simply display the URL in the address bar like this:
www.example.com/property-listings/united-states/colorado/denver/office-space
How do I accomplish this using htaccess and rewrite rules?
If I understood right, try writing a rule like this one:
RewriteEngine on
RewriteRule property-listings/united-states/colorado/denver/office-space http://www.example.com/property-listings/united-states/colorado/denver/denver-co-office-space [L]
OK. You didn't supply a pattern or mentioned there was any, so I have to guess the pattern is up to /denver/ subdirectory. Try this:
RewriteEngine on
RewriteRule ^(property-listings/united-states/colorado/denver/)(office-space)/?$ $1denver-co-$2 [L]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(property-listings/united-states/colorado)/(denver)/(office-space)/?$ $1/$2/$2-co-$3 [L,NC]

Remove folder with HTACCESS

When users go to the following url:
http://mysite.com/folder/subfolder?a=blah&b=blah
I need to point them to content that is in the root folder while keeping the variables intact:
http://mysite.com/?a=blah&b=blah
Since http://mysite.com is a virtual host, this solution should also leave other base URLs alone.
I'd prefer not to do a full redirect because we use log tracking in our system and we need to have the headers return a 200 code for the logs (maybe this doesn't matter).
I know that this is a fairly straightforward question for someone who really understands .htaccess redirects. Thanks in advance!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
RewriteRule ^folder/subfolder/?$ / [L,NC]

Rewrite subfolder to index.php file

i want to rewrite the url http://www.host.com/de/rss to the file http://www.host.com/index.php?type=9000001&L=1
My rewrite rule look like this:
RewriteRule ^de/rss(.*) index.php?type=9000001&L=1
But this does not work. If i delete de/ it works with the corresponding url.
I tried to look for similar questions here on stackoverflow, but that didnĀ“t help.
Use this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^de/rss/?$ index.php?type=9000001&L=1 [L,QSA,NC]
And if doesn't work then please post your full .htaccess in your question.
Maybe you should try this:
RewriteRule ^/de/rss.*$ /index.php?type=9000001&L=1

HTACCESS Redirect For Ecommerce Site

Could you please help to do a one off redirect in htaccess file from:
/something-something-something-something-c-2_19_70.html
to this type of file that does not have the number -2_:
/something-something-something-something-c-19_70.html
I am sure there is a short code that will get applied to all url of that type
Thank you very much in advance
David
Put this code in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# redirect /something-something-something-something-c-2_19_70.html
# to /something-something-something-something-c-19_70.html
RewriteRule ^(.*)2_(.*)$ $1$2 [L,NC,R]
# redirect /ethical-jewellery-silver-c-2_19.html to /silver-c-19.html
RewriteRule ^[^-]+-[^-]+-([^-]+-)([^-]+-)2_(.*)$ $1$2$3 [L,NC,R]

Resources