Centos 7 + VestaCP mod rewrite not working - mod-rewrite

First of all, i want to said, that i tried much ways from google but mod_rewrite not working!!
I tried from httpd.conf tried 1000000 way which i found on google, but still not working.
I want to remove .php from example.com/about.php
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
This is the one of example which i tried also in .htaccess but still no luck!!!!
Finally i want example.com/about but getting 404 not found, as i said, nothing worked for me which i found on stackoverflow or google

Seems no one posted Answer on my question, but if someone will enter to this question i resolved it :
Open /etc/httpd/conf/httpd.conf
Find all "AllowOverride None" and change with "AllowOverride All"
Check website, if not working, restart server.
Thats works for me!!

Related

YOURLS: 404 and directory issues

My main domain is smile.ws
I have installed yourls in smile.ws/yourls.
As a result, all my shortened urls are smile.ws/yourls/link instead of smile.ws/link
I followed the wiki instructions but that didn’t help.
I looked around and found a plugin called "Swap Short Url" which is supposed to help in these situations. It has slightly different .htaccess recommendation. I followed the instructions correctly and it works, because now the urls are smile.ws/link. But when you click on them, you get a 404 error.
How can I fix this? Thanks!
PS I know this is not a programming question. However, Stackoverflow has a tag for YoURLS that has 55 questions.
This to me sounds like it is related to the web servers .htaccess file but I can't be certain unless you can give us an example. I have a YOURLS site that work as you are describing without using a plugin. This really comes down to how the web server is configured and the YOURLS settings. Here is a sample of my .htaccess file.
# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS
In your config file this line needs to look like this.
define( 'YOURLS_SITE', 'http://smile.ws' );
If this doesn't work it might be due to your web server not having the correct permissions set or the rewrite module not enabled assuming you are using apache.
Did anyone check the root .htaccess?
# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /YOURLS/yourls-loader.php [L]
</IfModule>
# END YOURLS
This line needs to set the subdirectory /your dir here/
RewriteRule ^.*$ /YOURLS/yourls-loader.php [L]

CodeIgniter and specific rewrite rule

On my CodeIgniter site, I would like to add a specific rewrite rule, so that this url
http://www.exemple.com/cache.manifest
would rewrite to
http://www.exemple.com/controller/manifest
(because Safari 7 seems to only accept .manifest files for ApplicationCache)
So I try to add this line to my htaccess
RewriteRule ^cache.manifest$ controller/manifest
I added it before the other rewrite rules :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^cache.manifest$ controller/manifest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
But it returns a 404. If I change the line to
RewriteRule ^cache.manifest$ test.html
it works. So the first part on my rule is correct.
If I try to access directly to www.example.com/controller/manifest, it works to, so my url is correct.
I tried also
RewriteRule ^cache.manifest$ index.php/controller/manifest [L]
But it doesn't work either…
Any clue ?
Thanks a lot
I tried some tests on my local server and I think the following might work:
RewriteRule ^cache.manifest$ /index.php/controller/manifest [R,L]
I am not entirely sure if you need the leading "/" or "/index.php", so you
may need to experiment.
You need the [R] flag to force a redirect. In this situation, you want Apache
to look for the string cache.manifest in the URL, and then go to the CI page
controller/manifest.
It appears that you need to explicitly set the redirect.
Please let me know if this works. Good luck!

Remove particular segment from url

I am using Codeigniter for one of my apps and have a following htaccess file
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?$1 [L,QSA]
Now i have a url which is like mydomain.com/group/username
For SEO reasons i am suppose to convert this url into mydomian.com/group/username into mydomian.com/username using 301 redirect
Also urls like mydomain.com/group/username/page1 should redirect to mydomian.com/username/page
The closest i have tried after googling is by pasting this below line at the end of the file
RewriteRule ^(.*?)/?group(.*)$ /$1 [L]
But it isnt working.. any idea where i have gone wrong ?
The answers on other questions doesnt seem to be working for me/ Am pretty bad with .htaccess
P.S - i tried this
RewriteRule ^group/username(.*)$ username/$1 [QSA,R=301,L]
It works fine but it gives consecutive slashes like mydomain.com/username//pagename
I have figured it out
RewriteRule ^group/username(.*)$ username$1 [QSA,R=301,L]
This is will simply remove the 'group' from your URL and will do 301 redirect
If
RewriteRule ^group/username(.*)$ username/$1 [QSA,R=301,L]
gives two slashes, change it to:
RewriteRule ^group/username/(.*)$ username/$1 [QSA,R=301,L]
The (.*)$ matches anything after username (including the slash) until the end.

Hide "duplicate content" from Google after using mod_rewrite to remove .php file extension

Sorry for the somewhat cryptic title! I'll try to explain. I have the following in my .htacess:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
So users can type domain.com/foo/bar and domain.com/foo/bar.php is served. Of course, typing domain.com/foo/bar.php also loads the same page.
So, in Google Webmaster Tools (under HTML Suggestions), Google thinks that i have duplicated all my meta descriptions and title tags as it sees bar and bar.php as two different files. I am worried Google will penalise this "duplicate content". What should i do? I am sure im not the first one to have this issue, but i am struggling to find related questions/answers.
Thanks for any help
Use [R] (the redirect flag).
RewriteRule ^(.*)$ $1.php [R,L]
This forces an external redirect, so users who attempt to access domain.com/foo/bar.php will be redirected (through HTTP 302 Found) to domain.com/foo/bar. You'll also want to use [L] (last rule), so that the redirect happens immediately.
The answer i used (as per my original comment) from here which solved my problem
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php?\
HTTP RewriteRule (.+)\.php?$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(([^/]*/)*[^/.]+)$ /$1.php [L]

How to redirect all *.html pages to *.php pages?

I looked for the answer to this since it should be a rather common thing to do
and found some but the all lead me to an internal server error.. :(
i need to redirect all my html pages to their counter part in php
i know there is a rewriteRule i can use but cant seem to find the syntax..
a simple explenation:
i need to redirect all my *.html pages to *.php
I hope i explained it well.. would love your help or a link to some resources on this subject where i can really understand how to create this redirectRule
Create a .htaccess in the root folder of your site and place the following rules in it:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [L,R]
If you don't want the address bar to reflect the change, then change that last line to
RewriteRule ^(.*)\.html$ $1.php [QSA,L]
You can use RewriteRule:
RewriteEngine on
RewriteRule ^/(.*)\.html$ $1.php [R]
If you get Internal Server Errors, make sure that you have enabled mod_rewrite in apache :
sudo a2enmod rewrite
sudo /etc/init.d/apache2 reload

Resources