Category Archives: mod-rewrite

What is the best way to have an htaccess file rewrite if a string exists in the folder path

I have a url

.com/app/o/abc123xyz/index.php?somevar=someval

but when I load the URL I want it to load at

.com/app/index.php?index.php?somevar=someval&o=abc123xyz

HOWEVER, If the user accesses .com/app/index.php?somevar=somval, then know redirect occurs.

Also, I don't want the URL to actually change in the address bar.

I tried a variant of this...

   RewriteCond %{REQUEST_URI} /o/($a
   RewriteRule .* index.php

AND I tried a pattern similar to this, but I'm not seing where to add the conditional

    Options + FollowSymLinks
    RewriteEngine on
    RewriteRule index/(.*)/(.*)/$ ?$1=$2

htaccess error on root domain, need some custom rule

I have the following .htaccess file on my server and on the multi-language part the site works fine on all the pages except the root.

Get: ROOT_DOMAIN//?lang=en

Expect: ROOT_DOMAIN/en/

How can I achieve that?

RewriteEngine On
RewriteBase /

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]

# add a trailing slash    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

RewriteRule ^(payments)($|/) - [L]
RewriteRule ^(fr|pt|es|it|de|ru)/(.*?)/?$ $2.php?lang=$1 [QSA,L] 

Cakephp : AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error

My cakephp application is giving me this error:

[Tue Oct 16 14:31:10.079872 2018] [core:error] [pid 30667] [client ::1:56973] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://localhost/carte_drin/index.php

I configured my .htaccess this way:

/www/ :

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

www/carte_drin/app :

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$    webroot/    [L]
    RewriteRule (.*) webroot/$1    [L]
</IfModule>

www/carte-drin/app/webroot :

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
</IfModule>

I uncommented this statement in core.php:

 Configure::write('App.baseUrl', '/carte_drin/');

And the error is persisting.

Am I missing something or doing something wrong? Your answers and eventual helps are welcome.

Best

How can I use .htaccess to rewrite a file path on directory above current directory?

I am creating a project based on laravel PHP framework and apache2 server.

The application assets such as css, js and images are located in a directory outside the public directory,

application/grunt/dist/css application/grunt/dist/img application/grunt/dist/js

The .htaccess file is located under the public directory application/public/.htaccess

I want to write a rule in the .htaccess file such that when a file request is made to the assets (css,js,img) e.g example.com/assets/css/sample.css the rule should rewrite the path to return the path of the css file in application/grunt/dist/css/sample.css

How can I achieve this? .htaccess doesn't allow use of trailing slashes, i.e ../grunt/dist/

Redirecting index.php?p=product to /product/? (.htaccess URL Rewrite) [duplicate]

This question already has an answer here:

I'm using a simple script that parses and uses GET parameters to echo a simple output. The script is in the root folder:

domain.com/index.php?p=product

I simply want to change it to:

domain.com/product

while obviously still allowing the script at index .php to be able to see and process the GET requests. Note that "product" here is dynamic and could be any string of letters and numbers.

Note: Please assume I have a completely empty .htaccess file and have no idea what to put there (so would appreciate including any "opening/closing tags/header code").

On a side note, I've been trying to learn regex+mod_rewrite for like forever now and I just can't properly grasp it and always end up borrowing code snippets. Could you recommend a "from scratch" resource that explains it well?

Thanks!

Re-writing url – apache – htaccess

I am migrating an existing website to a Codeigniter one so need a help with re-writing of the urls.

I need to map old URLs with new URLs so that people visiting site from search engine results get redirected to matching new URLs as otherwise they would get page not found errors.

Most of the old urls in this format e.g.

/page.php?id=5 or /page.php?id=180&t=78
/data.php?token=GH45LK
/faqs.php?k=98#section2

Their matching new URLs are

/page/5 or I will be happy with /page?id=5&whatever=xyz too
/data/GH45LK
/faqs/98#section2

This is my current .htaccess of CodeIgniter

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # If you installed CodeIgniter in a subfolder, you will need to
    # change the following line to match the subfolder you need.
    # http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
    RewriteBase /

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the front controller, index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    # Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

I tried something like this after RewriteBase / line

RewriteRule ^data\.php\?token=(.*)?$ data/=$1 [R=301,L]

but not sure if I got that right as it's not working.

Could you help me getting it right? Thx

Hide text after .php?

I need to ask if it's possible to hide what appears after the ? for example, you have one link like this:

http://www.example.com/product.php?id=10

how can I hide the ?id=10, I'm already hiding the .php with the following code:

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [NC,L]

But I would like to know how can I hide what is after the ? because currently what it appears like this: http://www.example.com/product?id=10 and should appear like this: http://www.example.com/product

Can someone help me please?

extra www’s are added to the domain

I have modified the .htaccess file to force https. Now, I can not load my website anymore. When I open it, it automatically changes to www.www.example.com.

I have removed the .htaccess file but still problem not solved.

Here is the incriminated htaccess code:

Options All -Indexes 
DirectoryIndex index.php index.htm index.html 

RewriteEngine on 
RewriteBase / 

# Force HTTPS on the subdomains/subdirectories login or admin 
#RewriteCond %{HTTPS} off 
#RewriteCond %{HTTP_HOST} ^(login|admin)\. [NC] 
#RewriteCond %{REQUEST_URI} ^(login|admin)\. [NC,OR] 
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# Force WWW if no subdomain is given 
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ 
RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]