I am sure there are other threads on similar topics around the web. But I just can't get this working on my own website. Please help me
My site working in my subdomain
for eg http://demo.example.com/sitename/india
if i am put 1 parameter like (india) only. its loading profile.php?countryname=india also its working good.
But when i add multiple parameters into my url like this
http://demo.example.com/sitename/india/tamilnadu/chennai
i want load profile.php?countryname=india&state=tamilnadu&city=chennai .
I am try this code
RewriteCond %{HTTP_HOST} ^demo\.example\.com/sitename$
RewriteRule (.*) walola/$1/$2 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ sitename/profile.php?countryname=$1&state=$2 [QSA]
When i pass single parameter into my url its working otherwise its shows 404 error.
Please guide me.
***Answer***
RewriteCond %{HTTP_HOST} ^demo\.example\.com/sitename$
RewriteRule (.*) sitename/([^/.]+)/([^/.]+) [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ sitename/profile.php?countryname=$1&state=$2 [QSA]
Its Works good.
Please try this
RewriteRule ^(.*)/(.*)$ sitename/profile.php?countryname=$1&state=$2 [QSA]
or else send the full url to the profile.php page and split by using php.
i.e.,
RewriteRule ^/* sitename/profile.php?site=%{REQUEST_URI} [L,NC,QSA]
I would do it like this:
1. RewriteRule ^sitename/(.*) /sitename/profile.php/$1 [QSA,L]
2. In PHP: $args = explode("/", $_SERVER["PATH_INFO"]);
3. By var_dump($args) you will have idea how to deal with it.
Related
I have a working RewriteRule that rewrites any page to the literal url:
RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]
The problem is I want to add page=$1&category=$2 and convert it to...obviously... /category/page
I tried this, but it doesn't seem to work:
RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&category=$2 [QSA,L]
I should note that I would still like to be able to access pages without categories - ie /login or /about that should go to index.php?page=about for instance
Your solution will be as below.
RewriteRule ^([0-9a-zA-Z_\-]+)/([0-9a-zA-Z_\-]+)$ index.php?page=$1&category=$2 [NC,L]
Input url : http://www.test.com/my-cat/my-page
and it will be treated as : http://www.test.com/index.php?page=my-cat&category=my-page
Try with below, we are instructing apache to don't look for directory or file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?page=$1&category=$2 [QSA,L]
try this
#https://www.example.com/index.php?category=9&page=CBSE `#https://www.example.com/category/page/CBSE`
Method One:
#use this code for generate new url
RewriteRule ^index/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ index.php?category=$1&page=$2 [NC,L]
Method Two :
RewriteRule ^index/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ index.php?category=$1&page=$2
Note :Hit Your Url index.php?category=$1&page=$2 to convert $i & $2 Create Dynamic Url Your Id Bases
This will work for you.
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?category=$1&page=$2 [L]
If you want to generate rewrite urls easily, there are a lot online rewrite url generators.
Thanks for all the contributions...
Because I needed to cater for both /page and /category/page...I ended up doing this:
RewriteRule ^([0-9a-zA-Z_\-][^/]+)$ index.php?page=$1 [N]
RewriteRule ^([0-9a-zA-Z_\-]+)/([0-9a-zA-Z_\-]+)$ index.php?category=$1&page=$2 [L]
But that was only half the solution as I needed to modify my PHP to check whether category is set or not and to send a 404 if it doesn't match. Otherwise /invalid_category/valid_pagewould still work.
The ideas above all pushed me in the right direction, thanks.
I have a query on htaccess i need to rewrite a url like below example
www.example.com/parameater1/parameater2/parameater3/name=xyz
i need something like below
www.xyz.example.com/parameater1/parameater2/parameater3
i tried the below code
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.co\.uk$
RewriteRule ^(.*)$ "http://www.example.co.uk/test/$1/$2/$3?user=%1" [P]
but unable to resolve using the above code
Not best, but should work.
RewriteRule ^([^/]*/[^/]*/[^/]*)/name=(.*)$ http://www.$2.example.com/$1 [R=301,L]
I recently developed a web site using php which accepts a id as its input via get.
http://website.com/profile.php?id=123. its the old fashion way, I've seen sites use pretty url's like http://website.com/username.html
So in order to archive this, i managed to do some research and end up with this code blow.
Also i'm passing the username in the query string.
http://website.com/profile.php?id=123&username=test_user
the parameter ID is only used as a input for the profile.php
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /profile.php [NC]
RewriteCond %{QUERY_STRING} ^id=([^&]+)&username=([^&]+) [NC]
RewriteRule ^.* http://%{HTTP_HOST}/%2.html [R=301,L]
The final output i seek is http://website.com/username.html
Is their anything wrong in this ? this doesn't seem to work. Am i doing something wrong ? if so please be kind to let me know where my error lies. Thank you.
Try this rule:
RewriteEngine On
RewriteRule ^profile/([^/\.]+)/([^/\.]+).html/?$ profile.php?id=$1&username=$2 [L]
then you should be able to use
http://website.com/profile/123/username.html
as the URL. You can ignore the profile part but I don't recomment it because it would clash with other URLs of your website.
If you only need the username, use
RewriteRule ^profile/([^/\.]+).html/?$ profile.php?username=$2 [L]
and the URL would be
http://website.com/profile/username.html
You can use this rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} /profile.php\?id=([^&]+)&username=([^&]+) [NC]
RewriteRule ^ /%1/%2.html? [R=301,L]
RewriteRule ^([0-9]+)/([^/.]+)\.html$ profile.php?id=$1&username=$2 [L,QSA,NC]
been stuck at this for the past couple of hours here. Let me just illustrate my problem simply by the following lines.
Here's
1) Joomla absolute URL for the page i'm trying to convert: http://classifiedads4free.com/index.php?option=com_adsmanager&view=front
then:
Created menu item and activated SEF urls: So now alias becomes http://classifiedads4free.com/ads
after which:
I added a query string at the back of the URL so it becomes: http://classifiedads4free.com/ads?country=Singapore.
Was just wondering if there's anyway i can make the url at the top http://classifiedads4free.com/ads?country=Singapore. -->http://singapore.classifiedads4free.com
Tried going back to using the absolute URL on my .htaccess file, Following is the code:
1st tried:
RewriteCond %{HTTP_HOST} ^(.+)\.classifiedads4free\.com$
RewriteCond %{HTTP_HOST} !^www\.classifiedads4free\.com$
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|bmp)$ [NC]
RewriteRule (.*) ads?country=%1 [L]
2nd tried:
RewriteCond %{HTTP_HOST} ^(.+)\.classifiedads4free\.com$
RewriteCond %{HTTP_HOST} !^www\.classifiedads4free\.com$
RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|bmp)$ [NC]
RewriteRule (.*) index.php?option=com_adsmanager&view=front&country=%1 [L]
However, I can't seem to get the redirect working. It keeps redirecting me back to my home page which isn't what i requested.
Would appreciate if someone could provide some assistance here. Been trying all day long.
Try this:
RewriteRule ^(.*)$ http://www.classifiedads4free.com/ads?country=%1 [L,NC]
Well I'm making profile pages so right now it looks like this
http://example.com/random/?user=Robert
What I want to do is remove ?user= from the URL so the page appears as
http://example.com/random/Robert
Iv'e searched and I can't find anything working for me.
Thanks!
Based on http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html this should do the trick:
RewriteCond %{QUERY_STRING} ^user=(.*)$ [NC]
RewriteRule ^random$ random/$1 [NC,L,R=301]
The first step is to make all of your links in this form http://example.com/random/Robert, then in the htaccess file in your document root, add:
RewriteEngine On
RewriteRule ^random/(.+)$ /random/?user=$1 [L]
But to handle 301 redirects to your old URLs, you can include this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /random/\?user=([^\ ]+)
RewriteRule ^random/$ /random/%1 [R=301,L]