.htaccess file I can't make it working - regex

Disclaimer : I dont know anything about URL rewriting
currently my URL looks like
legalHQWithNewAddressTable/legalHQ/public/admin/Parties.php?caseid=7 (any number basically)
But how can I make it to looks like the following
legalHQWithNewAddressTable/legalHQ/public/admin/Parties/caseid/7/
I'm trying but not working RewriteRule ^([a-zA-Z0-9]+)/?
Please dont make things complicated I dont know anything about URL rewriting so please keep it as simple as possible.
Any Idea?

Try adding these rules to the htaccess file in the /legalHQWithNewAddressTable/legalHQ/public/ folder:
RewriteEngine On
RewriteBase /legalHQWithNewAddressTable/legalHQ/public/
RewriteCond %{THE_REQUEST} /admin/([A-Za-z0-9]+)\.php\?caseid=([0-9]+)&?([^\ ]*)
RewriteRule ^ admin/%1/caseid/%2/?%3 [L,R]
RewriteRule ^admin/([A-Za-z0-9]+)/caseid/([0-9]+)/ admin/$1.php?caseid=$2 [L,QSA]

Place this rule in your /legalHQWithNewAddressTable/legalHQ/public/admin/.htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /legalHQWithNewAddressTable/legalHQ/public/admin/
RewriteRule ^Parties/caseid/([0-9]+)/?$ Parties.php?caseid=$1 [L,QSA,NC]

Related

Remove query string and make clean url using htaccess

I have url's like following with query string. I want to remove query string from url and want to make clean url.
www.demo.com/following.php?user=hardik
www.demo.com/fans.php?user=john
This url's should be like
www.demo.com/hardik/following
www.demo.com/john/fans
OR should be like
www.demo.com/following/hardik
www.demo.com/fans/john
Is this possible with htaccess? I tried to find a loot in google but still no luck. Need help.
Update:
I need something like this
www.demo.com/user/hardik/following/
www.demo.com/user/john/fans/
I tried like this
RewriteRule ^user/([^?]*) following.php?user=$2/ [L,QSA]
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/(\w+)/(\w+)/?$ $2.php?user=$1 [L,QSA,NC]
Try with this for a url like www.demo.com/following/hardik
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z_-]+)/([a-zA-Z_-]+)/?$ $1.php?user=$2
Finally this is working for me for my last requirement. May be help someone else.
RewriteEngine On
RewriteBase /
RewriteRule ^user/([^*]+)/following/$ following.php?user=$1 [L,QSA]
RewriteRule ^user/([^*]+)/fans/$ fans.php?user=$1 [L,QSA]

Making user-friendly URL using .htaccess

I need to make my websites link user friendly. Currently, they look like this:
mydomain.com/post.php?title=News-Feeds-Latest-Addition-Puts-facebook-news-26
I want to make them look like this:
mydomain.com/title/get-back-your-recycle-bin-IT-news-85.html
I've written the following code into my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^title/([^/]*)\.html$ /post.php?title=$1 [L]
I don't know why, but it doesn't work. How can I get it to work?
You can use this code
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/post\.php\?(title)=([^\s&]+) [NC]
RewriteRule ^ /%1/%2.html? [R=302,L]
RewriteRule ^(title)/([^.]+)\.html$ /post.php?$1=$2 [L]
Use this :
RewriteEngine on
RewriteRule ^title/get-back-your-recycle-bin-IT-news-85.html/?$ post.php?title=News-Feeds-Latest-Addition-Puts-facebook-news-26 [NC]
now you can usethis url : mydomain.com/title/get-back-your-recycle-bin-IT-news-85.html

Can't match RewriteRule

I need to do a very simple URL rewrite but my RewriteRule is not working.
I want this URL: http://myweb.com:8080/MySite/bla?bla
To become this: http://myweb.com:8080/MySite/index.php
My .htaccess file content is like this:
RewriteEngine On
RewriteRule bla\?bla index.php
It is located in "MySite" folder. I can do other url-rewriting rules with success but I got stuck whenever I need to write a rule with question mark inside.
What am I doing wrong?
You need to use the %{QUERY_STRING} rewrite condition for this.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^bla$
RewriteRule ^/?bla$ index.php [NC,L]
Please, note that the ? in the rewrite rule is not there to match against the ? in the query string. That part is handled completely by %{QUERY_STRING}. The [NC] just makes the rule case-insensitive and [L] marks the rule as last.

mod_rewrite rule to change parent folder

Some unchangeable hyperlinks on a website point to /folderA/index.php?id=somestuff.
I need to redirect the Request to /folderB/index.php?id=somestuff instead.
I did some experimenting with this but I just can't get it to work, any help is appreciated.
RewriteEngine on
RewriteRule /folderA/index\.php\?id=([\w-]+)$ /folderB/index.php?id=$1
Keep in mind that RewriteRule doesn't match query string and matches only REQUEST_URI without it. Use this code instead:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+folderA/(index\.php\?id=[^&\s]+) [NC]
RewriteRule ^ /folderB/%1 [R=302,L]
Assuming that you are not planning on using different get request this should work:
RewriteEngine on
RewriteRule /folderA/index\.php\?id=(.*?)$ /folderB/index.php?id=$1

Mod-Rewrite for dynamic URLs

I'm trying to rewrite my URLs to be more SEO friendly, and I'm doing this in my .htaccess file using the following code:
RewriteEngine On
RewriteRule blog/(.*)/$ blog/index.php?&link=$1 [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
That code allows me to rewrite http://example.com/blog/index.php?link=22 into http://example.com/blog/page-title/
The only problem here, is that I'm trying to get it to work without the ending slash (/). I've tried removing it in the third line of the .htaccess code (right fater the $2), but that just breaks everything and the rewrite doesn't work at all.
Any help is greatly appreciated.
Try now, both with or without slash should work.
RewriteEngine On
RewriteRule blog/(.*)/?$ blog/index.php?&link=$1 [NC]
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2 [L,R=301]