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]
Related
A normal link of my site may look like this
mydomain.com/categorylist/8/Special_Single_Songs.html
I'm planning to change the URL pattern to something like
mydomain.com/categorylist/8-Special-Single-Songs.html
How can I redirect the old URL pattern to the new one using .htaccess redirect rule?
My .htaccess Rewrite rule look like this
RewriteRule ^categorylist/([0-9]+)/([0-9a-z]+)/([0-9]+)/(.*)\.html$ /index.php?pid=$1&sort=$2&page=$3 [L]
Try this code
RewriteRule ^categorylist/([0-9]+)/([0-9a-z]+)/([0-9]+)/(.*).html$ /index.php?pid=$1&sort=$2&page=$3 [L]
RewriteRule ^categorylist/([0-9]+)\-([0-9a-z]+)/([0-9]+)/(.*).html$ /index.php?pid=$1&sort=$2&page=$3 [L]
try this & put it on top after RewriteEngine on
RewriteRule ^categorylist([^_]*)_([^_]*_.*).html$ $1-$2 [L,NE]
RewriteRule ^categorylist([^_]*)_([^_]*).html$ /$1-$2 [L,NE,R=301]
note : big number of underscores can be a problem
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 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
Hi i have come across some urls of the type "http://localhost/jsfweb/cat/query/" where query is a string that will return some results from a mysql database. I am familiar with urls of the type "http://localhost/jsfweb/cat.php?query=query" how can i use those urls with php?
You can do this by rewriting url in htaccess file by this :
RewriteRule ^cat/(.*)$ cat.php?query=$1
Use modrewrite
You do something like this:
Inside a file named '.htaccess'
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
RewriteBase /php/eclipse/ShiftPlus2/
#forbidden area
#RewriteCond %{THE_REQUEST} index\.php
#RewriteRule ^index\.php$ http://localhost/php/eclipse/ShiftPlus2/? [R=301]
#unique case
RewriteRule ^email$ email.html [L]
#general case
RewriteRule ^([a-zA-Z_]*)/?$ index.php?query=$1 [L]
RewriteRule ^([a-zA-Z_]+)/([a-z]+)/?$ index.php?query=$1&action=$2 [L]
RewriteRule ^([a-zA-Z_]+)/(-?\d+)/?$ index.php?query=$1&id=$2 [L]
RewriteRule ^([a-zA-Z_]+)/([a-z]+)/(-?\d+)/?$ index.php?query=$1&action=$2$id=$3 [L]
RewriteRule ^([a-zA-Z_]+)/(\w+)/?$ index.php?query=$1&special=$2 [L]
#RewriteRule ^index.php$ login [R]
Where on the left side, there is a Rewrite rule with a regular expression and on the right, this is the real link like you know.
Take a look at Apache's mod_rewrite. For most of the websites it is done through that module. If you don't want to get your hands dirty with it, you can employ some sort of MVC framework that incorporates it.
Apache mod_rewrite is what you want. This is an excellent read for beginners:
10 Mod Rewrite Rules You Should Know
CodeIgniter (MVC framework) works by accepting a single entry point to the application, then routing according to what follows. So say you declare index.php as the default document, then /index.php/controller/view is the same as /controller/view. The parameters controller and view are used to instantiate and run the appropriate classes.
I'm just wondering how other websites replace there get variable.
example:
http://www.example.com/page.php?page=1
replaced:
http://www.example.com/page/1
indeed, just what ssx said.
You need a .htaccess file in the root of the website, with some content that looks like this (i use this one)
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([\(\)\|a-zA-Z0-9_-]+)/([0-9]+)/?$ /index.php?ext=$1&cat=$2&name=$3&urlID=$4 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([\(\)\|a-zA-Z0-9_-]+)/?$ /index.php?ext=$1&cat=$2&name=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/p=([0-9]+)/?$ /index.php?ext=$1&cat=$2&p=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ /index.php?ext=$1&cat=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /index.php?ext=$1 [L]
I'd say take a look at an answer I provided someone else a while back. I'd type it all out here again or copy and paste it but the link is much easier.
PHP dynamic DB page rewrite URL