How can I rewrite this URL using .htaccess - regex

How can I rewrite this URL
http://staging.felgenexklusiv.de/?felge=asa-gt1
to be displayed like this?
http://staging.felgenexklusiv.de/felge/asa-gt1
This is my existing .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Just before </IfModule> insert these lines:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(?:index\.php|)\?(felge)=([^\s&]*) [NC]
RewriteRule ^ %1/%2? [NC,L,R]
RewriteRule ^(felge)/(.*)/?$ /?$1=$2 [NC,L,QSA]

DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-zA-Z]+)/([a-zA-Z0-9\-]+)?/?(.*)$ index.php?partie=$1&name=$2&%{QUERY_STRING} [L,QSA]
</IfModule>

Related

htaccess RewriteRule and RewriteBase

i want hide a part of url
current url:
https://dev.karmagroup.com/karmamomentsnew/karma-postcards/
what i aim for is
https://dev.karmagroup.com/karma-postcards/
with the current .htaccess file :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /karmamomentsnew/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /karmamomentsnew/index.php [L]
</IfModule>
i tried to change the .htaccess like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /karmamomentsnew/(.+)$ $1 [L,NC,R]
</IfModule>
and it goes wrong surely, haha.. can somebody help me please. thank you before.
I've found this related question which answers your problem. The snippet from the answer is (note that it's adjusted to your needs)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^karmamomentsnew/)^(.*)$ /karmamomentsnew/$1 [L,NC]
Source: https://stackoverflow.com/a/18361995/5675325

htaccess URL rewrite - requested URL not found on server

Need to hide one folder while loading like Uniimart1609/S/page.php to Uniimart1609/page.php
in linux
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule Home_Page.php$ S/Home_Page.php
</IfModule>
is redirected http://Uniimart1609/Home_Page.php this is working fine, but when i rewrite the htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /S/$1.php [L,NC,QSA]
</IfModule>
getting The requested URL /S/Home_Page.php was not found on this server. Pleas help
Have your rule like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Uniimart1609/
RewriteCond %{THE_REQUEST} /S/(\S*) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/S/$1\.php -f [NC]
RewriteRule ^([^./]+)/?$ S/$1.php [L]
</IfModule>

htaccess for separate folder without disturbing homepage

I have wordpress installed in rootfolder in http://example.com . I have created new folder named world http://example.com/world , I need htaccess to work on that particular folder alone , Is it possible?
My htaccess I need to use for folder world is given below. I added this in rootfolder htaccess and I got internal server error and hence I don't want to disturb the root folder.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (.*)(\/?)$ / [QSA,NC,L]
My root folder htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Replace your DOCUMENT_ROOT/.htaccess with this code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# don't do anything for /world folder
RewriteRule ^world/ - [L,NC]
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Replace your DOCUMENT_ROOT/world/.htaccess with this code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /world/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]

Rewrite codeigniter URL with htaccess

I need to rewrite the URL by Apache mod-rewrite in Codeigniter
The page name is example.com/pages/page1
and i need to rename it by example.com/welcome.html
I wrote this rules in htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^pages/page1$ welcome.html [PT,L]
It doesn't work. How can i do that?.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^sys.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^app.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
assumming that index.php is your index page.
and change in config.php
$config['index_page'] = '';

Remove index.php from url using .htaccess for urls 127.0.0.1

I have my url in this way
http://127.0.0.1:420/github/myproject/users
and my .htacess file has the following code
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteBase /github/myproject
RewriteCond $1 !^(index\.php|images|style|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
Can you anyone help me how to write the RewriteRule expression that suits my url ? thanks for you help in advance
Just add this line on the top:
RewriteRule ^/github/myproject/(.*)$ /github/myproject/index.php/$1 [NC]
So it will become:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/github/myproject/(.*)$ /github/myproject/index.php/$1 [NC]
DirectoryIndex index.php
RewriteBase /github/myproject
RewriteCond $1 !^(index\.php|images|style|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
</IfModule>
Please tell me if it works for you!