I've been trying to get the mod_rewrite in my .htaccess file to work for the past few hours but I can't seem to pull it off. The .htaccess files definitely work on my server because I've used them before.
I've tried to rewrite it with this generator and testing it with this tool as well as on my server.
URL
I need to turn
http://someurl.com/news-detail.html?id=10&news=this-is-an-article
into
http://someurl.com/news/10/this-is-an-article
or
http://someurl.com/10/news/this-is-an-article
Rewrite
I've tried:
RewriteEngine On
RewriteRule ^([^/]*)/news/([^/]*)$ /news-detail.html?id=$1&news=$2 [L]
and
RewriteEngine on
RewriteRule /(.*)/news/(.*) news-detail.html?id=$1&news=$2 [L]
and
RewriteEngine on
RewriteRule news/([0-9]+)/([a-zA-Z_]+)$ news-detail.html?id=$1&news=$2 [L]
and many others.
I hope someone can help me out here..
Kindly check/add RewriteBase in your .htaccess file.
Also check if htaccess is allowed to rewrite or not.
Syntax is below
RewriteEngine on
RewriteBase /flodername/
RewriteRule ^urlinbrowser/(.*)/(.*)$ filename.php?first_param=$1&secondparam=$2 [L]
Keep your rules like this in root .htaccess:
RewriteEngine On
RewriteBase /dev/hoig/
RewriteCond %{THE_REQUEST} /news-detail\.html\?id=([^\s&]+)&news=([^\s&]+) [NC]
RewriteRule ^ %1/news/%2? [R=302,L]
RewriteRule ^([^/]+)/news/([^/]+)/?$ news-detail.html?id=$1&news=$2 [L,NC,QSA]
This will support /10/news/this-is-an-article URI structure for pretty URLs.
Related
I know it could be easily solved i just looked everywhere and tried everything without sucess so i had to ask here ;
how do i 301 redirect index.php?p=(number) or /?p= to product.php?id=(number) with htaccess.
I thought this might work but it didnt
RewriteEngine on
RewriteBase /
RewriteRule ^(index.php|?)p\=([0-9]+)$ product.php?id=$2 [R=301]
With your shown samples/attempts, please try following htaccess rules. Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /
RewriteCond %{THE_REQUEST} \s/index\.php\?p=(\d+)\s [NC]
RewriteRule ^ product.php?id=%1 [R=301,L]
I was trying to rewrite a URL for making my site SEO friendly, but .htaccess rewrite not seems to work.
My URL is
www.tasteofkochi.com/dine-detail.php?a=150
I need this to look like
www.tasteofkochi.com/sometext/150
I did the simple formula but it's not reflecting, intact nothing happens at all. If I add some junk char in htaccess, site crashes, which means htaccess is working fine. Also I added a formula to remove .php extn, and that too works fine. Only issue is with this one. Can anyone please help me. I enable rewrite in httpd and allow all in directories, still not working.
Below is my .htacces
RewriteEngine on
Options +FollowSymLinks -MultiViews
RewriteBase /
## hide .php extension
# To externally redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteRule ^detail/([0-9]+)/?$ dine-detail.php?a=$1 [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?p=$1 [L,QSA]
We can create pretty urls with .htaccess and php by mainly two files one is .htaccess and another index.php
Example
I'm banging my head on the wall with this one. I have a rewrite rule in my htaccess file which works for all urls but one. Here's the line
RewriteRule ^([a-zA-Z0-9_-]+)$ content.php?linkid=$1 [L]
And the complete htacess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
#RewriteRule ^contact-us content.php?linkid=contact-us [L,R]
RewriteRule ^([a-zA-Z0-9_-]+)$ content.php?linkid=$1 [L]
RewriteRule ^news/([a-zA-Z0-9_-]+)/([0-9]+)$ media.php?news=$1&pgNo=$2 [L]
RewriteRule ^news-details/([a-zA-Z0-9_-]+)$ media-detail.php?news_short=$1 [L]
RewriteRule ^services-list/([a-zA-Z0-9_-]+)$ services-list-new.php?services_list=$1 [L]
RewriteRule ^specialities/([a-zA-Z0-9_-]+)/([0-9]+)$ speciality-listing.php?speciality=$1&pgNo=$2 [L]
RewriteRule ^services-details/([a-zA-Z0-9_-]+)$ services.php?speciality_short=$1 [L]
RewriteRule ^treatment-detail/([a-zA-Z0-9_-]+)$ treatment-detail.php?treatment_short=$1 [L]
RewriteRule ^testimonial/([a-zA-Z0-9_-]+)/([0-9]+)$ testimonials.php?testimonial=$1&pgNo=$2 [L]
RewriteRule ^testimonial-detail/([a-zA-Z0-9_-]+)$ testimonial-detail.php?test_short=$1 [L]
RewriteRule ^photo-gallery-detail/([a-zA-Z0-9_-]+)$ photo-gallery-detail.php?photo_short=$1 [L]
RewriteRule ^media/([a-zA-Z0-9_-]+)/([0-9]+)$ media.php?media=$1&pgNo=$2 [L]
RewriteRule ^media-detail/([a-zA-Z0-9_-]+)$ media-detail.php?media_detail=$1 [L]
RewriteRule ^doctor-profile/([a-zA-Z0-9_-]+)$ doctor.php?doc_short=$1 [L]
RewriteRule ^make-an-appointment/([a-zA-Z0-9_-]+)$ make-an-appointmen.php?appointment_id=$1 [L]
RewriteRule ^current-openings/([a-zA-Z0-9_-]+)/([0-9]+)$ current-openings.php?current_opening=$1&pgNo=$2 [L]
</IfModule>
So this works for domain.com/privacy-policy which goes to domain.com/content.php?linkid=privacy-policy and a few others like testimonials, services, career etc
BUT, it doesn't work for contact-us, i.e. domain.com/contact-us
I've even tried the hard coded version above which is the commented line above. Any ideas guys?
EDIT:
I've tried using the url domain.com/content.php?linkid=contact-uswhich works correctly but domain.com/contact-us gives me the error The requested URL /contact-us was not found on this server..
I've also discovered another url that's not working and it is domain.com/media/list/1 which says The requested URL /media.html/list/1 was not found on this server. I don't know where it's getting media.html from. There was a file named media.html in the file structure so I removed that and the link started working. That's not the case with contact-us though.
Translating above comments into an answer as it might help someone with similar problems.
You need to disable MultiViews options to make it work.
So just change your Options line this:
Options +FollowSymlinks -MultiViews
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So if /file is the URL then Apache will serve /file.html.
I am trying to change my url using htaccess but it doesn't seem to be working. I want http://example.com/blog_view?id=1 to be changed to http://example.com/blog-id/1/ but it isn't working. I have tried using this.
RewriteEngine On
RewriteRule ^blog-id/([^/]*)/$ /blog_view?id=$1 [L]
You might have to add a RewriteBase directive:
RewriteEngine On
RewriteBase /
RewriteRule ^blog-id/([^/]*)/$ /blog_view?id=$1 [L]
You can test your rules with this tool
You need one redirect and one rewrite rule (already existing):
RewriteEngine On
RewriteCond %{THE_REQUEST} /blog_view\?id=([^\s&]+) [NC]
RewriteRule ^ /blog-id/%1? [R=302,L,NE]
RewriteRule ^blog-id/([^/]+)/?$ blog_view?id=$1 [L,QSA,NC]
I have a URL like -
http://www.mydomain.com/website/dev/main/html/about_us.html
How can I rewrite it to simply http://www.mydomain.com/about ?
I have seen many examples of URL rewrite on internet and SO but still couldn't figure it out. Any help would be appreciated.
Try this in your htaccess, make sure that mod_rewrite is actuvated on your server:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^about$ ./website/dev/main/html/about_us.html
Working from the Apache Rewrite Guide, your .htaccess file should contain:
RewriteEngine on
RewriteRule ^/about$ ./website/dev/main/html/about_us.html [R]
That turns the rewrite engine on (if it isn't already) and then sets up a rule. Any URL after the domain that matches the regex ^/about$ will be redirected transparently to /website/dev/main/html/about_us.html
I'm sure this is a repeat of an existing question. Make sure you have in your file:
RewriteEngine On
RewriteBase /
RewriteRule ^about$ website/dev/main/html/about_us.html
You can also pass vars this way too:
RewriteRule ^about/(.+)/(.+)$ about/index.php?q=$1&p=$2
Where about/12/23 would equal about/index.php?q=12&p=23