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]
Related
I have these rules that i want to make it work.
RewriteEngine on
RewriteRule ^/(view|show)/(ebook|lecture)/?$ page1.php?a=$1&b=$2 [L,QSA]
RewriteRule ^/(view|show)/(ebook|lecture)/([^/]+)/?$ page2.php?a=$1&b=$2&c=$3 [L,QSA]
RewriteRule ^/([^/]+)/-page-([0-9]+)?$ page3.php?a=$1&b=$2 [L,QSA]
My links are normally like this
www.domain.com/page1.php?a=view&b=ebook
www.domain.com/page2.php?a=view&b=ebook&c=title
www.domain.com/page3.php?a=title&b=6
and i want to turn them like the following look
www.domain.com/view/ebook //page1
www.domain.com/view/ebook/title //page2
www.domain.com/title/page-6 //page3
I've tried my rules but only the first one worked, But the page didn't load and the style was literally broken and not even a single image loaded or anything at all.
Try with:
RewriteEngine on
RewriteRule ^/?(view|show)/(ebook|lecture)/?$ page1.php?a=$1&b=$2 [L,QSA]
RewriteRule ^/?(view|show)/(ebook|lecture)/([^/]+)/?$ page2.php?a=$1&b=$2&c=$3 [L,QSA]
RewriteRule ^/?([^/]+)/page-([0-9]+)?$ page3.php?a=$1&b=$2 [L,QSA]
No leading slashes in left htaccess RewiteRule url (you can use RewriteRule ^(view...)
And you use only page- in your www.domain.com/title/page-6 //page3 link (not -page-)
I have the following rules in .htaccess:
RewriteRule js/jquery.min.js myproject/page/js/jquery.min.js
RewriteRule js/bootstrap.min.js myproject/page/js/bootstrap.min.js
RewriteRule styles/bootstrap.min.css myproject/page/styles/bootstrap.min.css
RewriteRule styles/bootstrap-theme.min.css myproject/page/styles/bootstrap-theme.min.css
RewriteRule styles/vinoservice.css myproject/page/styles/vinoservice.css
And also for images like that.
And my question is how can i specify a route like: every js/.js file serving the myproject/page/js/.js and of course for the styles also?
Thanks for the helps!
UPDATE
I tried this for them:
RewriteRule ^js\/.*(.js$) vinoservice/page/js/$1
RewriteRule ^styles\/.*(.css$) vinoservice/page/styles/$1
RewriteRule ^images\/.*(.png$) vinoservice/page/images/$1
RewriteRule ^images\/.*(.jpg$) vinoservice/page/images/$1
But not working correctly...but in regex generator says its good for them...interesting...what can be a problem? :S
You should only be concerned with the extensions if you wish to handle js/myscript.php differently, which I doubt you do.
As such, use the following:
RewriteRule js/([^/]+) myproject/page/$1 [L,R=301]
RewriteRule styles/([^/]+) myproject/page/$1 [L,R=301]
i know this is a common question but i cannot figure this one out.
I have the following URL:
http://buildsanctuary.com/viewbuild.php?id=3&title=this_is_a_title&page=1
What i wish is the URL to be:
http://buildsanctuary.com/viewbuild/3/this_is_a_title/1
Normally for mod rewrites i would send the user to the link i want and let htaccess do all the work.
So in this case i have tried linking the users to the preferred URL style and rewriting the URL but to no avail.
Any help on how i should be handling this? I want to send the users to the preffered URL but then can i use htaccess to allow me to process the page and URL $_GET information in the same way as the normal dynamic URL?
I have tried the mod rewrite generators etc but nothing works.
This is what the gens have given me:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.php$ /viewbuild.php?id=$1&title=$2&page=$3 [L]
Thanks.
Fix the generator rule:
RewriteRule ^viewbuild/([^/]*)/([^/]*)/([^/]*)\.php$ /viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]
However, I would do it this way:
RewriteRule ^([^/]*)/(.*) /$1.php/$2 [L]
and then map what you get in $_SERVER['PATH_INFO'] to you preference in PHP.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?id=$2&title=$3&page=$4 [L,QSA]
Should do the trick
^viewbuild/([0-9]+)/([a-z_]+)/-([0-9]+)/?$ viewbuild.php?id=$1&title=$2&page=$3 [NC,L]
Is it possible to somehow change my website links from:
domain.com/category.php?tag=test
domain.com/section.php?tag=test
domain.com/news.php?tag=test
into this:
domain.com/category-test
domain.com/section-test
domain.com/news-test
Thanks and have a good day!
You can achieve this using .htaccess and mod_rewrite. You'll need to create a .htaccess file with the following contents:
RewriteEngine On
RewriteBase /
RewriteRule ^category-([^/]+)/?$ category.php?tag=$1
RewriteRule ^section-([^/]+)/?$ section.php?tag=$1
RewriteRule ^news-([^/]+)/?$ news.php?tag=$1
Now, accessing domain.com/category-test/ will take you to category.php?tag=test.
If you'd prefer to have slashes instead of dashes, you can use:
RewriteRule ^category/([^/]+)/?$ category.php?tag=$1
RewriteRule ^section/([^/]+)/?$ section.php?tag=$1
RewriteRule ^news/([^/]+)/?$ news.php?tag=$1
RewriteRule ^category-([a-zA-Z0-9]+)$ category.php?tag=$1 [NC,L]
RewriteRule ^section-([a-zA-Z0-9]+)$ section.php?tag=$1 [NC,L]
RewriteRule ^news-([a-zA-Z0-9]+)$ news.php?tag=$1 [NC,L]
In "category.php" file get the tag $_GET['tag'];
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