htaccess error with query strings and rewriterule - .htaccess

I have a very annoying problem with my htaccess... This file's content on an other server were functioned flawlessly.
Now I had to move my site to other server and several conditions working, but this is not:
Options +FollowSymLinks
RewriteEngine on
RewriteOptions Inherit
RewriteBase /
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^firm\.php$ http://%{HTTP_HOST}/firm/details?id=%1 [R=301,L]
So when I have an url like this: www.domain.com/firm.php?id=35 then it should redirect to this url: www.domain.com/firm/details?id=35
One small note: The new engine I'm using is smarty 3 with codeigniter framework.
Thank you for your help!

Assuming it's the same .htaccess file that worked on the old server, the most likely reason is that the new one has a more restrictive AllowOverrides setting which is disabling mod_rewrite.

Related

Mod_Rewrite with .htaccess is not working

I just learnt about url-rewrite for my website with .htacess. My actual url is:
localhost/index.php?view=some-page
So i write this RewriteRule like this:
RewriteRule ^/([^/]*)/?$ /index.php?view=$1 [NC,L]
When i typed localhost/homepage on my browser, It does not work, it displays error 404 object not found. What have i done wrong please show me.
Many thanks
This should work in your DocumentRoot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?view=$1 [QSA,L]
Leading slash is not matched in htaccess.
are you using apache?
This link from step 6 helped me
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
When i was playing around with rewrites i had to enable it and tell apache where the pages were stored

htaccess rewrite query string nothing works

THE PROBLEM
After looking at 50+ StackOverflow posts and trying many permutations of my htaccess file, it does nothing still.
WHAT I HAVE TRIED
Using this website to generate my htaccess file: http://www.generateit.net/mod-rewrite/
Setting AllowOverride All in my httpd.conf file and restarting Apache.
MY CURRENT HTACCESS FILE
Lives in the root directory.
RewriteEngine On
RewriteBase /
RewriteRule ^find-a-local-doctor/([^/]*)/([^/]*)$ /find-a-local-doctor/?state=$1&city=$2 [L]
WHAT I WANT TO ACCOMPLISH
Change this URL:
http://www.md1network.com/find-a-local-doctor/?state=FL&city=Tampa
To this:
http://www.md1network.com/find-a-local-doctor/FL/Tampa
ADDITIONALLY
Since the actual file doing the work is: http://www.md1network.com/find-a-local-doctor/index.php, I need to be able to parse the query string with PHP. Hopefully, I will still be able to do this to get the state and city.
Please help.
Thanks.
Your existing rule looks alright but you will need an additional external redirection rule for reverse. Put this rule before your existing rule (just below RewriteBase /).
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(find-a-local-doctor)/(?:index\.php)?\?state=([^&]+)&city=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]

.htaccess URL Rewrite Failing - The requested URL was not found on this server

I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ /index.php?page=$1 [L,NC]
This works perfectly on one of my development machines running Apache. It does not work however on my other development machine running Apache (mod_rewrite listed in PHP info under apache2handler). Nor does it work on the live server, which I think is running Windows.
I have tried adding the following:
RewriteBase /
I'm no mod_rewrite wizard and I'm sure it's a very simple solution but it is eluding me currently and keep receiving a 404 not found error.
One thing that is different on the two environments in which this doesn't work, is that the site is not in the root of the URL. So for example it is http://localhost/site and www.example.com/site
I have tried various syntax adjustments in the .htaccess file, and also adding the site to the base:
RewriteBase /site
Remove the 'RewriteBase /site' and try removing the / before index.php
The slash should't be there with use of .htaccess
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1 [L,NC]

.htaccess Rewrite rules not firing

I am trying to come up with a rewrite rule that will rewrite:
oldurl.com/v11/file.ext to newurl.com/v11/file.ext
On the oldurl server I have put the following in .htaccess inside of the folder v11:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^v11/(.*)$ http://newurl.com/v11/$1 [R=301,L]
But the redirect is not firing at all. What did I do wrong?
When placing .htaccess in the v11 folder, your code should be:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ http://newurl.com/v11/$1 [R=301,L]
Check that the new server is set up to allow .htaccess files to be read at the directory level.
If the .htaccess file worked on the other server, it is most likely a server configuration issue or file owner/permissions problem.

PHP page access without extension and variable

How can I create a PHP page system that we access without .php extension and without ?page= variable?
There's a simple exemple:
http://www.exemple.com/portfolio/1
Instead of:
http://www.exemple.com/portfolio.php?id=1
It would be great for me because I'm a web designer and this is a thing I never did. So it would be good to know this! Also I will use this in my website.
you would need the following in your .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule .+ %1.php [QSA,L]
You're looking for mod_rewrite.
RewriteEngine On
RewriteRule ^/profile$ /account.php?profile [L]
Create .htaccess file in your web root and enter following.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^account/([0-9]+)$ account.php?id=$1
OR
See mod_rewrite, in case URL rewriting, if you trying to do such.
You can use multiviews, or better and more used: mod_rewrite module from apache. It can be via a .htaccess file where you create rewrite rules like
RewriteEngine On
RewriteRule ^(.*)?(.*)$ /$1.php?Action=$2 [L]

Resources