Current code to use index.php for all urls :
RewriteRule ^(.*)$ ./index.php
But for one special case, I want to make url
http://domain.com/s/this_changes to call actually
http://domain.com/steps/step/this_changes.
I tried adding :
RewriteRule ^./s/$ ./steps/step/$1, but it gives an error 500.
Try this:
RewriteEngine On
RewriteRule ^s/(.+)$ /steps/step/$1 [L]
Another way you could do it is to route all your URIs through index.php, and create a function for each one.
RewriteRule ^s/this_changes$ steps/step/this_changes
if it is that simple or
RewriteRule ^(.*)/(.*)$ steps/$1/$2
And your specific code would work like this
RewriteRule ^s/(.*)/?$ ./steps/step/$1
The (.*) is referenced in your $1 in the second part of your code.
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 am trying to get my htaccess to rewrite the url to display two folders rather than two vars.
Here is my url:
www.MyWebsite.com/index.php?p=info&id=1234
That is actual url but I want it to display this:
www.MyWebsite.com/info/1234
Here is the code for the htaccess but it does not work for the second var.
DirectoryIndex index_good.html index.php
RewriteEngine On
RewriteBase /tjshow/
# RewriteRule ^([\w\-]+)/*$ ?p=$1 [L]
# RewriteRule ^([\w\-]+)/([\w\-]+)/*$ ?p=$1&id=$2 [L]
RewriteRule ^([\w\-]+)/*$ index.php?p=$1 [L]
RewriteRule ^([\w\-]+)/([\w\-]+)/*$ index.php?p=$1&id=$2 [L]
RewriteRule ^([\w\-]+)/([\w\-]+)/([\w\-]+)/*$ index.php?p=$1&id=$2&link=$3 [L]
The first one works fine but the second one is giving me a page but with all kinds of internal broken links and images.
This one works:
www.MyWebsite.com/index.php?p=info
And it displays this only, which is what I want it to do:
www.MyWebsite.com/info
But if I add the second var there like this
http://mywebsite.com/tjshow/second
Then the code breaks.
Try using this rule instead:
RewriteRule ^([^/]*)/([^/]*)$ /index.php?p=$1&id=$2 [L]
Using the above rule will leave you with the URL: www.MyWebsite.com/info/1234
Take this url for example:
www.mysite.com/old/blablabla/some.html
I want to replace any request uri starting with /old/ with /new/old/.
Then that sample should be
www.mysite.com/new/old/blablabla/some.html
I tried this but I got 404:
RewriteCond %{REQUEST_URI} ^/old/
RewriteRule ^/old/(.*)$ /new/old/$1 [L]
Just with this:
RewriteRule ^/old/(.*) /new/old/$1 [L]
but /new/old/blablabla/some.html has to exist phisicaly in your server path.
I have the following htaccess rewrite rules
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3
Now the thing is, the first rewrite rule works just fine
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
It's just when I try using the others, only name get variable is being passed and not
$_GET['season']
or
$_GET['episode']
i know it's most likely something simple I'm missing or have done, but I just can't seem to get it working.
Give this a try:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^shows-watch/([^/]+)/season-([^/]+)/episode-([^/]+).html?$ show.php?name=$1&season=$2&episode=$3 [QSA,NC,L]
RewriteRule ^shows-watch/([^/]+)/season-([^/]+).html?$ show.php?name=$1&season=$2 [QSA,NC,L]
RewriteRule ^shows-watch/([^.]+)\.html?$ show.php?name=$1 [QSA,NC,L]
The order is very important so they don't overlap you also need the L flag to stop when needed.
This assumes your .htaccess is on the root folder of your domain along with the show.php file and that you are accessing it like this:
domain.com/shows-watch/Show Name.html
domain.com/shows-watch/Show Name/season-1.html
domain.com/shows-watch/Show Name/season-1/episode-10.html
The first line gets all the links because it matches all the links.
Try reverse the order:
RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3
RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
Or you can exclude slashes like this:
RewriteRule ^shows-watch/([^/]*).html?$ show.php?name=$1
RewriteRule ^shows-watch/([^/]*)/season-([^/]*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/([^/]*)/season-([^/]*)/episode-([^/]*).html?$ show.php?name=$1&season=$2&episode=$3
So I have mydomain.tld, www.mydomain.tld and res.mydomain.tld all pointing to the same directory: /var/www/mydomain. In that directory, there's my codeigniter application.
So what I'm trying to do is to forward all requests made through res.mydomain.tld to a specific controller called resources.
What I have:
RewriteCond %{HTTP_HOST} ^res\.mydomain\.tld$
RewriteRule ^(.*)$ /index.php?/resources/$1 [L]
This produces a server error, my rewrite log doesn't provide any clues about why; it just shows some very weird logic being applied to the request string.
Any idea of why this isn't working?
Leave your .htaccess was before.
In your routes.php
if($_SERVER["SERVER_NAME"]=="res.mydomain.tld"){
$route['default_controller'] = "resources";
}else{
//$route['default_controller'] = Your default controller...
}
You created a infinite loop. It keeps on rewriting, because the rules always match, and match again. Just add a rule like the following above your rule
RewriteRule ^index.php - [L]
This will prevent any remaining rules underneath it from executing if the (already rewritten) url starts with index.php
Make sure that index.php isn't matching and going into a rewrite loop:
RewriteCond %{REQUEST_URI} !^index\.php
RewriteCond %{HTTP_HOST} ^res\.mydomain\.tld$
RewriteRule ^(.*)$ /index.php?/resources/$1 [L]