500 error with mod re-write cannot see whats wrong? - mod-rewrite

I have been using mod re-write ok up until now.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/?(shopping-catalogue)/([0-9]+) index.php?friendly_url=$1&view=catalogue&catalogue_id=$2 [L]
RewriteRule ^/?(shopping-catalogue)/(category)/([0-9]+) index.php?friendly_url=$1&view=$2&category_id=$3 [L]
RewriteRule ^/?(shopping-catalogue)/(category-item)/([0-9]+) index.php?friendly_url=$1&view=$2&category_item_id=$3 [L]
RewriteRule ^/?(shopping-catalogue)/(category-item-option)/([0-9]+) index.php?friendly_url=$1&view=$2&category_item_option_id=$3 [L]
# marketing module see newsletter before sending
RewriteRule ^/?(newsletters)/([A-Za-z0-9-]+)/(newsletter)\.html /newsletters/$2/newsletter.html [L]
RewriteRule .([^/]+)\.html index.php [L]
#RewriteRule ^/client-area/CLID/([0-9]+) /index.php?temp=template_dataroom&CLID=$1 [L]
# allow access with no restrictions to local machine at 192.168.1.3
RewriteCond %{REMOTE_ADDR} !192.168.1.3
# allow access to all .css and .js in sub-directories..
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
# allow access to the files inside img/, but not a directory listing..
RewriteCond %{REQUEST_URI} !dataroom/(.*)\.
RewriteRule ^files/([^/]+)/([^/]+).zip /download.php?section=$1&file=$2 [NC]
# allow access to these particular files...
My problem seems to be that this line gets ignored
# marketing module see newsletter before sending
RewriteRule ^/?(newsletters)/([A-Za-z0-9-]+)/(newsletter)\.html /newsletters/$2/newsletter.html [L]
I am trying to access an html file directly but the folder is a unique name each time.... ie -
http://www.awebsite.co.uk/newsletters/template_4fd09c5b429ea/newsletter.html
This line is being ignored. I do not understand why?
Any help would be much appreciated.
Thanks
Andi

ok I got it working now,. Took the / off the redirected link
Here is the line I now have
# marketing module see newsletter before sending
RewriteRule ^/?(newsletters)/([A-Za-z0-9_]+)/(newsletter)\.html newsletters/$2/newsletter.html [L]
Thanks
Andi

I haven't checked the result but you do not seem to be allowing the underscore
RewriteRule ^/?(newsletters)/([A-Za-z0-9-]+)/(newsletter)\.html /newsletters/$2/newsletter.html [L]
RewriteRule (newsletters)/([A-Za-z0-9|-|_]+)/(newsletter)\.html /newsletters/$2/newsletter.html [L]
Also, I don't think you need to starts with bit (^).

Related

HtAccess Laravel

Please find my Laravel website URL below: www.webrox.ae
This website problem is that.. It opens /index.php and for all menu items like portfolio or hire us etc it it opens name/oservices/public/portfolio.. Something like this,....
Below is my htaccess file
Please Guide
#Alternate default index page
DirectoryIndex www.webrox.ae/index.php
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
# Change 'subdirectory' to be the directory you will use for your main domain.
# Don't change the following two lines.
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?webrox.ae$
RewriteCond %{REQUEST_URI} !^/oservice/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /oservice/public/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?webrox.ae$
RewriteRule ^(/)?$ webrox.ae/index.php [L]
RewriteCond %{HTTP_HOST} ^www\.webrox\.ae$
RewriteRule ^/?$ "http\:\/\/webrox\.ae\/" [R=301,L]
Thanks
Change the line from
RewriteCond %{REQUEST_URI} !^/oservice/public/
RewriteRule ^(/)?$ webrox.ae/index.php [L]
to
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^(/)?$ webrox.ae [L]
And add the line
RewriteRule ^ index.php [L]

htaccess file for codeigniter on subdomain virtualhost

i have problem about .htaccess file for my codeigniter installation.
On localhost this work fine, when i upload online its rewrite URL but the website not work.
this is my htaccess on localhost:
RewriteEngine On
RewriteBase /jCore_01/
#RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
online i have a problem:
i put this file on subdomain jcore.miodomio.com and it rewrite URL but not work
example:
without htaccess it's work:
jcore.miodominio.com/index.php/en/home
with htaccess
jcore.miodominio.com/en/home
Not Found
The requested URL /en/home was not found on this server.
can anyone help me? suggestion?
regards
Denny
Try change your htaccess to:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Somethings to consider.
Did you enable Apache rewrite module?
If enabled check whether your virtual host file is configured properly So to make sure its hitting .htaccess or try putting some dump on .htacess , So if its hitting .htaccess than you should get an 500 server error.
If you are not getting error than its mostly the problem in your host settings.

Unable to properly redirect with .htaccess

I'm tring to redirect the following paths on our old site:
/apps
/apps/about
/apps/everything_else
/site
To a different subdomain using the following RewriteRule:
RewriteRule ^site/?$ http://site.newsite.com [R=301,NC,L]
but nothing happens, is anything wrong with this rule? Also, how do I add the apps to the same rule?
Will the following work:
RewriteRule ^site/?|apps(/.)?$ http://site.newsite.com [R=301,NC,L]
You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(apps|site).* [NC]
RewriteRule .* http://site.newsite.com/ [R=301,L]
Maps silently:
http://site.oldsite.com/apps or
http://site.oldsite.com/apps/anything or
http://site.oldsite.com/site or
http://site.oldsite.com/site/anything
To:
http://site.newsite.com/
Nothing is passed to the substitution URL as the OP does not mention that requirement in the question.
Strings apps and site are assumed to be fixed.
For silent mapping, replace [R=301,L] with [L]

How to redirect an url with parameters?

I'm at a total loss trying to integrate a mod_rewrite in my existing page. Currently, I am building a new site from scratch, and there i have some nice clean url's such as:
http://www.example.nl/nl/example
The old site, running Cms made simple, has some not-rewritten url's that would need to be redirected to the new pages. Those url's look like this:
http://www.example.nl/index.php?page=cake-and-pie&hl=nl_NL
But shorter versions of that like:
http://www.example.nl/index.php?page=cake-and-pie
also work.
It took me a while to figure out that url's with parameters cannot simply be redirected with "Redirect 301", like i'd normaly do. So i tried some online mod_rewrite generators like this and this, but the rules outputted by those result only in 404 errors, (the redirect doesn't work at all).
My .htaccess file current looks like this:
RewriteEngine On
RewriteBase /
# remove .php;
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
The old pages would seize to exist.
How do i redirect the old pages to the new ones?
Thanks.
EDIT
RewriteCond %{QUERY_STRING} =page=pie
RewriteRule ^index\.php$ /nl/? [L,R=301]
RewriteCond %{QUERY_STRING} =page=pie&hl=nl_NL
RewriteRule ^index\.php$ /nl/? [L,R=301]
Seems to do the trick. This is of course manual for every url, but i only have a few.
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/([^/]+)/?$ index.php?page=$1&hl=$2
RewriteRule ^([^/]+)/?$ index.php?page=$1 [QSA]

Mod rewrite most requests to index.php

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
##RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.(js|ico|gif|jpg|png|css)$ [NC]
RewriteCond %{REQUEST_FILENAME} !^index.php [NC]
RewriteCond %{REQUEST_FILENAME} !^$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
## RewriteRule ^/([a-zA-Z_+-]+).php$ index.php?p=%1 [R=301]
## RewriteRule ^/?([-a-zA-Z0-9_+]+)$ index.php?p=$1 [R=301,L]
## RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php?b={REQUEST_FILENAME}
RewriteRule * index.php?p={REQUEST_FILENAME} [R=301,L]
Above you can see my attempts to redirect any request that is not an existing directory, is not index.php and is not a static resource to redirect to index.php?p=resourcename
I am not having any luck. Basically the purpose of this is to redirect static and old urls to new ones as I have just rewritten an old site.
The PHP will handle the redirect logic.
At the moment this code causes an internal server error, I assume because it is caught in a redirect loop. What have I done wrong? My brain is fried after a long day.
Untested, but worth a try :
RewriteRule .* /index.php?p={REQUEST_FILENAME} [R=301,L]
The ".*" part means you want to match 1 or more characters (any of them). And the "/" in front of the "index.php" is probably not mandatory but makes things clearer even if you have the RewriteBase option set to "/" already.
You may also want to add the parameter "QS" between the brackets, to be sure to get the querystring that may be passed with the queries (would be [QS,R=301,L]). Hope this works, and this helps :)
Edit: There's also the "%" in front of "{REQUEST_FILENAME}", as stated by Gumbo.
This code eventually solved my problem.
Thanks for the help, though.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^/?([-a-zA-Z0-9_+]+).php$ /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([-a-zA-Z0-9_+]+)$ index.php?p=$1 [L]
You forgot the % in front of the variable (%{REQUEST_FILENAME}) and an expression that should be repeated zero or more times (* is just a quantifier):
RewriteRule .* index.php?p=%{REQUEST_FILENAME} [R=301,L]

Resources