Rewrite subfolder to index.php file - .htaccess

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

Related

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]

.HTACCESS Rewriting Issue

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]

.htaccess simulate directories

I want to redirect /services/websites.html to just websites.html in my head directory. That way I will be able to put all my files in the head directory so all css files and stuff like that will be linked correctly. I tried:
RewriteRule ^services/websites.html$ websites.html
But that does not work. I figured it is something simple but I couldn't find anything on Google.
Could you help me?
This is the code you need to put in your .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^services/(.*)$ $1 [L,NC]
try:
RewriteRule ^.*websites\.html$ websites.html
Please note the html not hmtl in your example.

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