snach15 Posted January 22, 2013 Report Share Posted January 22, 2013 sveiki, ierakstu caur webu datus iegš htaccess, saturs izkatās šādi RewriteRule abcd123 index.php?re=1 RewriteRule useris index.php?re=2 RewriteRule markus index.php?re=3 bet man vajadzētu tā lai pārbauda saturu pirms ierakstīšanas lai nevar ierakstīt piemēram vēlreiz šādus datus, vards kas atrodas aiz RewriteRule nedrīkst atkārtoties, pretējā gaījumā izmestu erroru un datus neierakstītu. RewriteRule markus index.php?re=1 RewriteRule markus index.php?re=2 kā lai to panāk? mana scripta source $name = "4"; $link = "markus"; $htaccess = fopen('.htaccess', 'a'); fseek($htaccess, -13, SEEK_CUR); fwrite($htaccess, 'RewriteRule '.$link.' index.php?re='.$name."\n"); fclose($htaccess); Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted January 22, 2013 Report Share Posted January 22, 2013 Tu tiešām katram userim gribi rakstīt savu rewrite rule? Quote Link to comment Share on other sites More sharing options...
snach15 Posted January 22, 2013 Author Report Share Posted January 22, 2013 nē, man galvenais to principu uztaisīt. Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted January 22, 2013 Report Share Posted January 22, 2013 Es domaaju, ka to ko gribi panaakt var izdariit nesaapiigaak - saki ko tu gribi panaakt. Padod skriptam tos vaardus un dabuuni ID (vai arii kas tas buutu) no datubaazes. Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 22, 2013 Report Share Posted January 22, 2013 Kāpēc tu šādā veidā mēģini pārrakstīt .htaccess? To dara mazliet savādāk: 1. Uztais all-over rewrite: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> 2. Saglabā tos datus DB ( ar PHP varēsi easy pārbaudīt, lai dati nedublētos ): short_urls: +---------+----+ | name | re | +---------+----+ | abcd123 | 1 | | useris | 2 | | markus | 3 | +---------+----+ 3. Ievadod http://lapa.lv/useris/ pārbaudi php līmenī urli un uzstādi attiecīgos parametrus, piemēram: $path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); $url = trim( $path, '/' ); $stmt = $db->prepare( "SELECT re FROM short_urls WHERE name = ?" ); $stmt->execute( array( $url ) ); $row = $stmt->fetch(); if ( $row ) { $_GET['re'] = $row['re']; } Šādi varēsi arī aliasus taisīt urļiem utt. Tas tā, uz ātru roku. Quote Link to comment Share on other sites More sharing options...
snach15 Posted January 22, 2013 Author Report Share Posted January 22, 2013 tieši tas ko man vajg, bet izkatās sarežģīti ... paldies! mēģināšu samocīt Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 22, 2013 Report Share Posted January 22, 2013 Nav tur nekā sarežģitā. Ja atcerēšos vēlāk, tad pēc darba uzcepšu mazu demo lapeli paraugam. Quote Link to comment Share on other sites More sharing options...
snach15 Posted January 22, 2013 Author Report Share Posted January 22, 2013 rezultātu panācu savādāk, bez datubāzes un tikpat efektīvi RewriteRule re/(.*) index.php?re=$1 [L] Quote Link to comment Share on other sites More sharing options...
aaxc Posted January 22, 2013 Report Share Posted January 22, 2013 Ja tev der http://lapa.lv/re/markus, tad jā. Tikai tev php pusētikuntā vajag izanalizēt requestu. Quote Link to comment Share on other sites More sharing options...
snach15 Posted January 22, 2013 Author Report Share Posted January 22, 2013 izdarīju to jā, nu nebija tieši tāds variants kā gribēju bet vismaz linku stipri saīsināju. Un viss darbojas tieši kā vajadzētu. Mans pirmais posts salīdzinoši bija pilnīgi muļķīga sistēma , bet nu no kļūdām jāmācas :) anyway paldies! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.