In my config file, I have:
$config['url_suffix'] = "/";
Here is my .htaccess:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^.+[^/]$
RewriteRule ^(.+)$ $1/
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
When I load a page, I don’t get the trailing slash. I am using URI routing, but even when I go to the actual path of the controller/view, I still don’t get the trailing slash.
What am I doing wrong? I tried removing the slash after the .php in the last line of the .htaccess, but that didn’t do it.
Even if I add “.html” as my URL suffix, it doesn’t get added. And that’s not in my .htaccess.
If I try to make $route['news-and-events'] = "news"; this instead: $route['news-and-events/'] = "news"; I get a 404 error
EDIT: With the above .htaccess I get an error that I am using disallowed characters, even when I add "/" to my allowed characters string in the config file.
Found a one that worked for me, Imported my Blogger posts to my Wordpress, and then my back links didn't work, so I just replaced my .htaccess with this example, check it out!
http://www.high-on-it.co.za/2011/02/removing-trailing-html-from-url/
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Related
This is my .htaccess in the root directory that's supposed to get rid of "public" from URLs:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
This is my .htaccess in the public directory that's supposed to get rid of trailing slashes:
<IfModule mod_rewrite.c>
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
</IfModule>
This is all well and good, except that when I enter a URL with a trailing slash, it redirect back to a URL with no trailing slash, but also with /public added.
For example, we have this route:
Route::get('/de', 'HomeController#index')->name('home');
Normally, the URL looks like domain.com/de.
But, if I type in domain.com/de/ into the browser, it redirects to domain.com/public/de instead of to domain.com/de - and the page loads as normal.
How do I fix this?
Your site root .htaccess should be like this:
RewriteEngine On
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301,NE]
# route all requests to public/
RewriteRule ^(.*)$ public/$1 [L]
Then inside public/.htaccess have this code:
RewriteEngine On
# if /public/ is part of original URL then remove it
RewriteCond %{THE_REQUEST} /public/(\S*) [NC]
RewriteRule ^ /%1 [L,NE,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Make sure to completely clear your browser cache before testing this change.
Apache/Nginx should be pointing to the public directory instead of the project root.
This way you don't need to add any .htaccess rule to get rid of the "public" string in the URLs
I'm using Apache 2.2 with two servers:
Development: localhost/project/public
Production: www.example.com
I have an existing rewrite rule for clean urls (to remove 'index.php' from the url).
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have one special route that only works if a trailing slash is present:
special route (development): localhost/public/documentation/
special route (production): www.example.com/documentation/
How do I add a rewrite rule to my existing .htaccess to always add a trailing slash, but only for the documentation route?
You just need to add another RewriteRule that matches only against /documentation i.e. without a trailing slash. The first rule adds the trailing slash and then your existing rule adds the index.php.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(documentation)$ $1/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If you would like the browser's address bar to also reflect the trailing slash change the rule to
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(documentation)$ $1/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Don't forget to add these directives first once per .htaccess file:
Options +FollowSymlinks
RewriteEngine on
And then you can try this:
RewriteRule ^/?(documentation)$ /$1/ [R,NC,L]
Or this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} (.+)/([^/]+)$
RewriteRule ^/?(documentation)/(.+)$ /$1/$2/ [R,NC,L]
I'm confused about your question..
How to redirect all pages (pages only) to index.html using htaccess file and not redirect the image files. For some reason I am using this code and an image file on the index.html page isn't showing up.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .* /index.html [L,R=302]
Try this code :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.html [L,R=302]
Keep your rules simple. Instead of filtering what shouldn't match, just match on the files.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .*\.(php|html)$ /index.html [L,R=302]
A nicer way might be just to ignore existing files. For example:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* / [L,R=302]
The !-d says to ignore the rewrite if there is an existing directory that meets the match.
The !-f says to ignore the rewrite if there is an existing file that meets the match.
Everything else will get rewritten.
You need to add a .htaccess file inside the public directory, so whenever you build your app, it automatically gets copied to the new dist directory. The content of.htaccess should be like:
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
Add the following before the last line
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$
We are finding it difficult to remove the redirection of my /admin to /index.php/admin, which is not allowing us to access the admin panel, at every url that should start with /admin/ gets redirected to /index.php/admin/ and it displays No input file specified. and when i remove index.php from the url it works fine.
My .htaccess file looks like this
DirectoryIndex /new/magento-k/index.php
RewriteEngine on
RewriteBase /mysubdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_URI} !^/admin.*
RewriteCond %{REQUEST_URI} ^/index.php/admin.*$
RewriteRule ^/index.php/admin(.*) /admin$1 [R]
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule ^/index.php/(admin|user)($|/) - [L]
Options -MultiViews
Try putting this into your .htaccess file
RewriteRule .* /index.php [L]
and remove the other index.php rule:
RewriteRule ^/index.php/(admin|user)($|/) - [L]
Also make sure to clear cache of Magento and your browser.
I have a doubt about url rewriting using apache mod_rewrite. I am a newbie in mod_rewrite and I don't have any experience in regex.
What I want to do is to:
Rewrite / To /web/content/public/
Rewrite /clients/ To /web/content/clients/
How can I achieve above things.
I tried:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/clients/$ web/content/clients/ [L]
RewriteRule ^(.*)$ web/content/public/$1 [L]
</IfModule>
But it doesn't work. What can I do?
^(.*)$ includes the slash. So don't include the slash in the rewritten pattern.
But include a root slash at the head of your rewritten pattern.
RewriteRule ^/clients(.*)$ /web/content/clients$1 [L]
RewriteRule ^(.*)$ /web/content/public$1 [L]
Check the apache access log and error log to see what kind of request URL comes back.
Please check the documentation, especially the list labeled "Here are all possible substitution combinations and their meanings:"
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^/clients/$ web/content/clients/ [L]
RewriteRule ^/(.*)$ web/content/public/$1 [L]
And if you want to use that rules in a .htaccess file, remove the leading slash from the patterns.