I had a Plesk Onyx server, running on Centos 7.2, Apache 2.4 Nginx is OFF, I had the following htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.js|\.css|\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.ttf|\.woff|\.woff2|\.otf|\.eot|\.ico|\.svg|\.txt|\.xml|\.json)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder1/folder2/([0-9]+)/(.*)[/]$ /folder1/folder2/index.php?get_var=$1 [NC,QSA,L]
The rwwite works OK but its not passing the get_var
in index.php I had a var_dump ($_GET) and it is empty if I visit
https://sample_domain.com/folder1/folder2/123/
I want to get the 123 value into the get_var
tried disabling -MultiViews and no luck
That rule can't be working at all for the URL you presented. It would only work for something like:
https://sample_domain.com/folder1/folder2/123//
Or:
https://sample_domain.com/folder1/folder2/123/example/
Try this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/folder1/folder2/index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder1/folder2/([0-9]+)/$ /folder1/folder2/index.php?get_var=$1 [NC,QSA,L]
I removed unnecessary tests since it could only be a directory. And I guess you don't even need that test? Do you have existing directories in /folder1/folder2/ named only with numbers? If not remove that test to improve performance.
Update
To operate this out of a .htaccess file in /folder1/folder2/, change it to be as follows:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ index.php?get_var=$1 [NC,QSA,L]
Related
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?-([^/]+)? product-details.php?pro_slug=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/?-([^/]+)? blog-details.php?n_slug=$1&n_id=$2 [L,QSA]
this will working for only first defined page product-details.php. please help.
I am hitting on www.test.com/blog/Want-to-transfer-your-home-loan-to-another-bank, www.test.com/product/agriculture-land-near-by-agra First url should be served by product-details and 2nd one should be served by blog-details.php file.
Based on your shown samples, please try following htaccess Rule file.
Make sure to clear your browser cache before testing your URLs.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(blog)/([\w-]+)/?$ product-details.php?pro_slug=$1&id=$2 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(product)/([\w-]+)/?$ blog-details.php?n_slug=$1&n_id=$2 [NC,L,QSA]
For some reason stylesheets and images are not loading on my site :(
Don't really know why I believe it may be to do with my htaccess file here is how it currently is.
UPDATE - NEW FILE
#SetEnv APPLICATION_ENV development
DirectoryIndex /public/index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) $1 [L]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
RewriteRule ^(.+) /public/$1 [L]
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php?q=$1 [L,QSA]
RewriteRule !\.(js|ico|gif|jpg|png|css|xml|xslt)$ /public/index.php
Any idea why its not loading?
It looks like there has been some cut-and-pasting: 'RewriteEngine on' should be there only once and the code from that point is causing you trouble.
The reasons for those lines are not clear without more info on the kind of site you run, so any advice from here is trial and error testing:
The last rule is commented out and looks like an effort to get the stylesheet and images (all js|ico|gif|jpg|png|css|xml|xslt files) correctly rewritten to the desired address. You can try to comment it out (get rid of the #).
The problem was fixed by rewriting the whole file to the following
DirectoryIndex /public/index.php
RewriteEngine On
Options +FollowSymLinks -MultiViews -Indexes
RewriteBase /public
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(domainUrlNoHttp)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^http://(domainUrl)$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
I'm trying to rewrite the url of a certain php file.
Aim for url: www.mysite.com/filename/topic/ or www.mysite.com/filename/topic
What works: www.mysite.com/filename and www.mysite.com/topic
I've tried all rewrite rules I know which should work, but every time I add the topic to the url I end up with a 500 internal server error
Current .htacces file
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
//No need for php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
//Rewriting the url
RewriteRule ^([a-zA-Z0-9_-]+)$ filename.php?topic=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ filename.php?topic=$1
You have conflicting rules and there is probably an issue with content negotiation with MultiViews. Also you aren't using all the flags ([L]) need to prevent continuation of rules matching.
You can't do it that way with the second set of rules and you don't need 2 rules just to have a / or not. You can make it optional. You need to do something like this.
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?topic=$2 [L]
</IfModule>
I've got Apache 2.4.4 running on Windows 8 laptop (WAMP server) and I found a really odd behavior of .htaccess mod_rewrite rules.
I want to redirect the root of my website to a specific file. My .htaccess looks like this:
RewriteEngine On
RewriteBase /
RewriteRule $^ /static/home.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ router.php?url=$1 [L,QSA]
This works only if there's no index.php file in root directory. When I create index.php file, Apache redirects empty path straight to the index file and doesn't bother with the first RewriteRule.
Is there a way to have both these RewriteRules and index.php file working together? In oher words, my example works but I want to rename router.php to index.php and keep both RewriteRules working.
Thanks!
You can just tweak your regex pattern to work in both situation:
DirectoryIndex something-else.php
RewriteEngine On
RewriteRule ^$ /static/home.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
I have been using a .htaccess on different server successfully using apache but for some reason I can not get it to work on this new hosting package as I keep getting the "Page not Found" screen with the following message: "The requested URL /about-us was not found on this server".
Urls in browser look like this: www.mysite.com/about-us
My code is as follow:
RewriteEngine on
Options +FollowSymlinks
DirectoryIndex index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?mode=$1 [L,QSA]
Any help appreciated
thanks
Your favicon.ico condition may be breaking the match. To negate a pattern, use only ! instead of negating the lexicographically equal match.
RewriteEngine on
Options +FollowSymlinks
DirectoryIndex index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^favicon\.ico [NC]
RewriteRule ^(.*)$ index.php?mode=$1 [L,QSA]