i dont know what error in my url rewrite - .htaccess

I am trying to rewrite my url using the htaccess file, but it does not work. I have enabled mod_rewrite and Allow Access, but still it does not work for local and online. What is wrong with my rewrite code?
I want to rewrite this url
http://example.com/post/post.php?pid=104
like this
http://example.com/post/post-pid-104.htm
This is my htaccess code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule post-pid-(.*)\.htm$ post.php?pid=$1

This should work: RewriteRule post.php?pid=(.*)$ post-pid-$1.htm$

The rewrite lines are fine, it looks like it's a problem with your server configuration.
You can test your rewrite rules with this: http://htaccess.madewithlove.be/

Related

htaccess to remove part of a url, .htaccess

I was wondering how it is possible to remove part of a url with htaccess for example I have a url like this:
http://localhost/item.php?pa=gd34392
now I need to use htaccess to redirect this page or anything like this to a page with this url:
http://localhost/gd34392
I have tried things like this but nothing seems to work and I do not really know my way around htaccess
RewriteEngine on
RewriteRule item.php?pa=$1 /$1 [R=301,L]
You can achieve that using the following rules in your .htaccess:
RewriteEngine On
RewriteRule ^([^/]*)$ /item.php?pa=$1 [L]
Just make sure you clear your cache before testing this.

rewrite url /blog/article.php?id=hello to /blog/hello.html

Im having some troubles with the redirection rules on my .htaccess file.
I would like to create a rule to redirect my blog content to a friendly url.
The current url structure is:
/blog/article.php?id=hello
and I would like it to change to:
/blog/hello.html
This are my rules so far, and I dont seem to be able to find the error:
RewriteEngine On
Options -MultiViews
RewriteRule ^blog/([a-z,A-Z,0-9]+)$.html blog/article.php?id=$1 [L]
Any help would be appreciated.
Because of your placement of $ in the pattern, the rewrite module is unable to match your request to the expression.
It should be:
Options -MultiViews
RewriteEngine On
RewriteRule ^blog/([\da-z]+)\.html$ blog/article.php?id=$1 [L,NC]

Rewrite example.com/index.php/... to example.com/... using mod_rewrite and .htaccess

I am migrating my site from Wordpress to Jekyll and I would like to keep the URLs working. My idea was to use a .htaccess file for this and to place it in the root of the site. But unfortunately after trying several tutorials and generates it doesn't seem to work.
The old URLs have the following format
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
The new URLs have this format:
http://example.com/2016/05/07/title-of-the-blog-post.html
Among others I've tried this example which looks good to me, but it actually casues all pages on my site to display an error message :)
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^index.php.*$ http://example.com/ [R=301,L]
I think that should take all URLs that start with example.com/index.php and make them start with example.com/, but apparently that is not the case.
To redirect
http://example.com/index.php/2016/05/07/title-of-the-blog-post/
to
http://example.com/2016/05/07/title-of-the-blog-post.html
you can use the following rule :
RewriteEngine on
RewriteRule ^index\.php/(.+)$ http://example.com/$1.html [NE,L,R]
or alternatively you can use mod_alias like that:
RedirectMatch 301 ^/index\.php/(.+)$ http://example.com/$1.html

My htaccess not working in my website but working in testing site

Finally, I managed to write htaccess code and tested it in http://htaccess.madewithlove.be/ and found its correct.
The way the URL is rewritten in this http://htaccess.madewithlove.be/ is working
but when I use the same htaccess code in my website is not working.
new URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/login.php
Actual URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/index.php?r=site/login
Htaccess code
RewriteEngine On
RewriteRule ^qjyii2/yii2dev3/frontend/web/([^/]*)\.php$ /qjyii2/yii2dev3/frontend/web/index.php?r=site/$1 [L]
My mod_rewrite is working fine in server. I did put this htaccess under /www/qjyii2/yii2dev3/ and its not working. Any help is highly appreciated.
If you're placing this in /www/qjyii2/yii2dev3/.htaccess then use this code:
RewriteEngine On
RewriteBase /www/qjyii2/yii2dev3/
RewriteRule ^(frontend/web)/([^/]*)\.php$ $1/index.php?r=site/$2 [L,NC,QSA]
.htaccess is per directory directive and Apache strips the current directory path from RewriteRule URI pattern.

URL rewrite not working -htaccess

I want to rewrite my site URL structure to a SEO friendly url using htaccess file.
I want to rewrite this URL:
/Site/mysite/tags.php?tag=tag
to
/Site/mysite/tags/tag
This is my script:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /tag/(.*)\.php tags.php?tag=$1
other commands such as DirectoryIndex working properly but my above code not.
i know this question asked before but i can not fix this problem. excuse me please!
thanks.
Your script would rewrite /tag/foo.php to tags.php?tag=foo. What you need is
RewriteRule ^/tag/(.*) /tags.php?tag=$1
Try this code rather :
RewriteEngine on
RewriteRule ^Site/mysite/tag/(.*)$ /Site/mysite/tags.php?tag=$1

Resources