htaccess url shortening works locally not on server - .htaccess

I wonder if anyone can take a look at this htaccess and tell me why it should work on a localhost but not on server
Options +FollowSymlinks
RewriteEngine On
RewriteBase /subdirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^news(.*)$ news.php?q=$1 [L,QSA]
RewriteRule ^view/([^/]+)/([^/]+).html /view.php?content_id=$1&content_id=$2 [NC]

Try to remove RewriteBase /subdirectory or rename it to RewriteBase /.

Related

301 Redirect Dynamic URL

OK so I have the following as part of the URL: /user/26872-essi/
and I'm going to final URL of /essi/
I currently have:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^user\/([0-9]+)\-.+[/]?$ /user.php?user_id=$1
So I tried:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^user\/([0-9]+)\-.+[/]?$ /$2/ [R=301,L]
RewriteRule ^(((?!\.|\/).){1,})\/?$ /user.php?username=$1
It doesn't seem to be passing the variable in. Any ideas what I could be doing wrong?
You may use these rules in your site root .htaccess:
RewriteEngine On
RewriteRule ^user/\d+-([\w-]+)/?$ /$1/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ user.php?username=$1 [L,QSA]

.htaccess url: rewrite is not working at local host Xampp

My current url is
http://localhost/www.zeeshan.com/user.php?name=zeeshan06
I want to display my url as
http://localhost/www.zeeshan.com/user/zeeshan06
I use the following code but it not working
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Options +FollowSymlinks
RewriteBase /
RewriteRule ^user/(.*)user.php?name=$1 [R]
Please help me to solve my problem. Thanks.
If you place this .htaccess inside the folder www.zeeshan.com:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www.zeeshan.com/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([^/]+)$ user.php?name=$1 [NC,L]
And access the URL:
http://localhost/www.zeeshan.com/user/zeeshan06
It should lead you to:
http://localhost/www.zeeshan.com/user.php?name=zeeshan06
// http://localhost/Milan_Practice/Milan_Mvc/routing.php?name=about
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /Milan_Practice/Milan_Mvc/routing\.php\?name=([^&]+)
RewriteRule ^ /Milan_Practice/Milan_Mvc/routing/%2/%3?%4 [L,R=301]
RewriteRule ^/?Milan_Practice/Milan_Mvc/routing/([0-9]+)/(.*)$ /Milan_Practice/Milan_Mvc/routing.php?name=$1 [L,QSA]

.htaccess file not redirecting url

I have this .htaccess file which simply reroute URL from primary link ex- http://www.mywebsitename.com/somepage.php?id=some_id to http://www.mywebsitename.com/somepage/some_id
Here is the code for that-
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.ashurocks.in$
RewriteRule ^(.*)$ http://www.ashurocks.in/$1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/([a-zA-Z0-9]+)$ /user.php?u=$1 [QSA]
RewriteRule ^group/([a-zA-Z0-9]+)$ /group.php?id=$1 [QSA]
RewriteRule ^article/([a-zA-Z0-9]+)$ /article.php?id=$1 [QSA]
It was working properly and I was able to get the content. But now, It's not working. Whenever I visit the URL http://www.mywebsitename.com/somepage/some_id, it does not redirect me to http://www.mywebsitename.com/somepage.php?id=some_id .
Is there something wrong with this .htaccess file code?
OK I got it.
I simply used Options +FollowSymLinks -MultiViews before the line RewriteEngine on and it solved my problem

My .htaccess pretty url not working which is in localhost (local machine with xampp)

I need to rewrite this url :
http://localhost/blog/post.php?id=48
into
http://localhost/blog/post/48
which is in localhost of my xampp.
I have created .htaccess file and wrote the below code to work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([0-9]+)/?$ post.php?id=$1 [NC,L]
</IfModule>
I have tried redirection and all other stuff. Everything is working but my rewrite rule alone not working. I've searched and tried all options but i couldn't succeed. Plz anyone help me out on this!!
Finally its working with below code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/ # This is the thing which made me struck with this
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([0-9]+)/?$ post.php?id=$1 [NC,QSA]
</IfModule>
The ^post is your problem, this implies that post is the first part of your path, which it's not - blog is. Have you tried ^blog/post...:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/post/([0-9]+)/?$ blog/post.php?id=$1 [NC,L]
</IfModule>

How can I simplify my url with .htaccess?

I would like this:
http://www.website.com/test/view
to actually call this:
http://www.website.com/index.php/test/view
I tried an .htaccess file that looks like this but it doesn't seem to work:
RewriteEngine on
RewriteCond $1 !^index\.php
RewriteRule ^(.*)$ /index.php/$1 [L]
What am I missing?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php%{REQUEST_URI} [L]
Did you set "RewriteEngine On" At The first line??
I used this once and it worked fine for me:
RewriteEngine On
RewriteRule ^([a-z\-]+)$ /index.php?page=$1 [L]

Resources