I saw a lot of similar questions, but I couldn't solve this problem with their answers..
I'm trying to do a URL Rewrite by converting
http://example.com/myfile.php?var1=42&var2=aString
to
http://example.com/mydir/42/aString
I tried the following RewriteRule 's (one by one) :
RewriteRule ^mydir/([0-9]+)/(.*)/(.*)$ myfile.php?var1=$1&var2=$2 [NC,L]
RewriteRule ^mydir/([0-9]+)/(.+)/(.+)$ myfile.php?var1=$1&var2=$2 [NC,L]
RewriteRule ^mydir/([0-9]+)/?$/?$ myfile.php?var1=$1&var2=$2 [NC,L]
I couldn't get them work..
What am I doing wrong? and how can I make it work?
Thanks !
You have 3 groups but only two parameters, try with two groups
RewriteRule ^mydir/([0-9]+)/(.*)$ myfile.php?var1=$1&var2=$2 [NC,L]
Related
I've been searching and cannot find an answer that suits my needs. It is a rather simple question I assume.
The point is that I need to rewrite my files to a name of my liking. For example I have, 'www.mydomain.com/account_index.php' which I want to rewrite to www.mydomain.com/account
Thus far I had this, but that doesn't seem to work with multiple lines.
Rewriteengine on
rewriterule ^support account_ticket.php [L]
rewriterule ^account account_index.php [L]
So in short, I want my website to redirect /account to account_index.php and the other way around.
Thanks in advance!
I found the answer for those that are wondering.
I had to put a RewriteCond before every RewriteRule.
So if I wanted to go to www.mydomain.com/account. I'd have this:
RewriteCond %{REQUEST_URI} ^/account$ [NC]
RewriteRule ^account account_index.php [NC,L]
This means that /account is now linked to account_index.php.
Have a nice day!
I have this rewire rule: EDITED
RewriteRule ^(.*)$ $1.php [NC]// the problem is caused by this. How can I keep it without having this result?
RewriteRule ^user/(.*)$ user.php?user=$1 [NC]
RewriteRule ^ride/(.+)/$ ride.php?myRideId=$1 [NC,L]
when I do this:
www.example.com/ride/123
everything works fine and my browser correctly shows the above page but if I try to use:
$rideId = $_GET['myRideId'];
echo $rideId;
the result is:
123.php/123
I don't understand why. Anything wrong in the rewrite rule?
Have you tried doing this?
RewriteRule ^ride/(.+)/?$ ride.php?myRideId=$1 [NC,L]
Try this. Also you will need to write your URL as:
www.example.com/ride/123/
I know this problem is over asked, but couldnt find anything fitting with my problem.
I'm currently creating a website, and my url are like :
www.foo.com/
or www.foo.com/index.php.
They can take 1, 2 ,or three different parameters like
www.foo.com/index.php?page=Home&lang=en&article=1
What i'd like is an url like
www.foo.com/Home/
or www.foo.com/en/Home
or www.foo.com/Article/1
or www.foo.com/en/Article/1
The page parameter is required, other two are not..
I cant have anything working for me... Any help would be greately appreciated
Thanks a lot !
Better to have separate clean rules. Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^([a-z]{2})/([^/]+)/?$ /index.php?page=$2&lang=$1 [L,QSA]
RewriteRule ^([a-z]{2})/([^/]+)/([0-9]+)/?$ /index.php?page=$2&lang=$1&article=$3 [L,QSA]
RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&article=$2 [L,QSA]
Try something like this
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)/([a-z0-9_-]+)\.html$ index.php?param1=$1¶m2=$2¶m3=$3
I am new to .htaccess and I seem to be having some problems getting it to clean up the url for me.
I have
site.com?p=article&id=3&read=article title
I am able to get the first variable to work ok like site.com/articles. but when I try to go further the server is saying it cant find it. I have tried several methods none of which seem to be working.
RewriteRule ^([a-zA-Z0-9]+)$ index.php?p=$1
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?p=$1
this above is working
I have tried
RewriteRule ^([a-zA-Z0-9-z\-]+)(/([a-zA-Z0-9-z\-]+))?/?$ index.php?p=$1&i=$2
and
RewriteRule ^([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)/?$ index.php?p=$1&i=$2&read=$3
the last 2 are not working. help please. Thanks
Let's try something like this?
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?p=$1&id=$2&read=$3 [L]
%{QUERY_STRING} is what you are looking for.
this is what I use for a similar situation:
RewriteRule ^/(.*) /index.php?r=/$1&%{QUERY_STRING} [L]
What would be the apache rewrite url to extract the id number (434376) from this url?
http://stackoverflow.com/questions/434376/unique-url-slug
something like
RewriteEngine On
RewriteRule ^questions/([0-9]+)/?$([A-Za-z0-9-]+) post.php?post_id=$1 [NC,L]
...but it doesnt work on my site...any tips?
thanks
Tested:
RewriteRule ^questions/([0-9]+)/?.*$ rewrite.php?post_id=$1 [NC,L]
Well if the / is optional it probably should be:
RewriteRule ^questions/([0-9]+)/?([A-Za-z0-9-]+)?/?$ post.php?post_id=$1 [NC,L]
Let me know if it works..