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
Related
I have a small website on Simple PHP with different folders/sections and files working with different Parameters.
i.e.
http://www.domain.com/folder1/file1.php?id1=66&id2=title_name
http://www.domain.com/folder1/file2.php?id1=85&id2=11&id3=title_name
MY TRY
RewriteRule "^/dummy1/(.*)/(.*)/" "/folder1/file1.php?id1=$1&id2=$2"
RewriteRule "^/dummy2/(.*)/(.*)/(.*)/" "/folder1/file2.php?id1=$1&id2=$2&id3=$3"
Please help me
Try :
RewriteRule ^/?dummy1/(.*)/(.*)/?$ /folder1/file1.php?id1=$1&id2=$2 [QSA,NC,L]
RewriteRule ^/?dummy2/(.*)/(.*)/(.*)/?$ /folder1/file2.php?id1=$1&id2=$2&id3=$3 [QSA,NC,L]
Haay!
Have a question about ModRewrite for apace webserver.
recently i have fixed one of my urls:
Before: http://pagename.com/index.php?sideID=home
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)$ index.php?sideID=$1
After : http://pagename.com/home
Now I have a more advanced problem when I want to pass more variables trough URL
to create my blogg.
currently: http://pagename.com/index.php?sideID=blogg&id=12&title=a-great-blog-post
I would like this to be more clean and structured, I want somthing like:
http://pagename.com/blogg/12/Gratulerer-FEEL-GOOD-med-ny-hjemmeside
I have tested something like this:
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?sideID=$1&id=$2&title=$3
without any success, any anwser leading to my success will be highly aprecciated :)
Here is my current .htaccess file:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?sideID=$1
RewriteRule ^bloggg/([^/]+)/([^/]+)/([^/]+)/?$ index.php?sideID=$1&id=$2&title=$3 [L,QSA]
Use this additional rule:
RewriteRule ^blogg/([^/]+)/([^/]+)/([^/]+)/?$ index.php?sideID=$1&id=$2&title=$3 [L,QSA]
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]
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]
My current code is
RewriteRule ^(.*)$ index.php?pg=$1 [L,QSA]
index.php?action=product shop.com/product
index.php?action=product/add shop.com/product/add
Now I want to add paging to some of the pages, something like
index.php?action=product&page=1&show=20 shop.com/product/1/20
index.php?action=product/add&page=1&show=20 shop.com/product/add/1/20
How do I do this?
RewriteEngine On
RewriteRule ^product$ index.php?action=product
RewriteRule ^product/add$ index.php?action=product/add
RewriteRule ^product/(\d+)/(\d+)$ index.php?action=product&page=$1&show=$2
RewriteRule ^product/add/(\d+)/(\d+)$ index.php?action=product/add&page=$1&show=$2
I suggest taking a look at this answer too. I think it would be better in this case.