htaccess url kürzen get

02/15/2021 21:32 Cc_Cc_Cc#1
Hallo,

ich weiß es gibt etliche Beispiele wie man eine url kürzen kann aber ich habe soviele ausprobiert und verstehe es warum es bei mir nicht funktioniert?

Ganz simples beispiel:

Ich will meine URL von

[Only registered and activated users can see links. Click Here To Register...]

zu

[Only registered and activated users can see links. Click Here To Register...]

machen.

Was ist an dem Code falsch?


Fehlermeldung:

02/16/2021 03:01 elmarcia#2
Quote:
Originally Posted by Cc_Cc_Cc View Post
Hallo,

ich weiß es gibt etliche Beispiele wie man eine url kürzen kann aber ich habe soviele ausprobiert und verstehe es warum es bei mir nicht funktioniert?

Ganz simples beispiel:

Ich will meine URL von

[Only registered and activated users can see links. Click Here To Register...]

zu

[Only registered and activated users can see links. Click Here To Register...]

machen.

Was ist an dem Code falsch?


Fehlermeldung:

It should be something like this:


Btw if your planning to make MVC pattern your rewrite rule should look sth like this:

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
QSA handles query strings or sth im not an expert in php :rolleyes:


Edit:
Rewrite rule for removing index.php?page={anything} and replacing with /{anything}
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} page=(.*)
RewriteRule . %1? [L,R]

#RewriteRule . index.php [L]
02/16/2021 05:19 Cc_Cc_Cc#3
Quote:
Originally Posted by elmarcia View Post
It should be something like this:


Btw if your planning to make MVC pattern your rewrite rule should look sth like this:

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
QSA handles query strings or sth im not an expert in php :rolleyes:


Edit:
Rewrite rule for removing index.php?page={anything} and replacing with /{anything}
Code:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} page=(.*)
RewriteRule . %1? [L,R]

#RewriteRule . index.php [L]
thanks it works but I get this error again:
Not Found
The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

my files are in the folder pages and my index file is on this folder: /
02/16/2021 18:40 elmarcia#4
Quote:
Originally Posted by Cc_Cc_Cc View Post
thanks it works but I get this error again:
Not Found
The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

my files are in the folder pages and my index file is on this folder: /

Code:
RewriteEngine On
RewriteBase /

# Prevent looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

# Rewrite if not index.php page
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

# Change url from page={something} to {something} and redirect
RewriteCond %{REQUEST_URI} /index.php
RewriteCond %{QUERY_STRING} page=(.*)
RewriteRule . %1? [L,R]
This will work but, you cannot pass query string in index.php other than page.

localhost/home -> will be interpreted as index.php?page=home
localhost/index.php?page=home -> will redirect to -> localhost/home
02/16/2021 20:01 Cc_Cc_Cc#5
Quote:
Originally Posted by elmarcia View Post
Code:
RewriteEngine On
RewriteBase /

# Prevent looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

# Rewrite if not index.php page
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

# Change url from page={something} to {something} and redirect
RewriteCond %{REQUEST_URI} /index.php
RewriteCond %{QUERY_STRING} page=(.*)
RewriteRule . %1? [L,R]
This will work but, you cannot pass query string in index.php other than page.

localhost/home -> will be interpreted as index.php?page=home
localhost/index.php?page=home -> will redirect to -> localhost/home
thank you it works, but now my homepage has no CSS style. Because the htaccess redirects the css style to index.php
02/17/2021 16:08 elmarcia#6
Quote:
Originally Posted by Cc_Cc_Cc View Post
thank you it works, but now my homepage has no CSS style. Because the htaccess redirects the css style to index.php
Sorry forgot to add these lines:

RewriteEngine On
RewriteBase /

# Prevent looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

# Rewrite if not index.php page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

# Change url from page={something} to {something} and redirect
RewriteCond %{REQUEST_URI} /index.php
RewriteCond %{QUERY_STRING} page=(.*)
RewriteRule . %1? [L,R]